android 创建快捷方式
2014-05-06 10:00
363 查看
通过launcher源码可以看到创建快捷方式是通过
- <receiver android:name="com.android.launcher2.InstallShortcutReceiver" android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
- <intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
生成快捷方式
我们可以在程序启动时直接发送广播创建桌面快捷方式
private void createShortCut(){
Intent intent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//action
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));//快捷方式名字
intent.putExtra("duplicate", false); //是否重复创建快捷方式
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , BatteryProfile.class)); //启动界面
sendBroadcast(intent);//发送广播
}
我们需要在在mainfest.xml加入以下权限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
- <receiver android:name="com.android.launcher2.InstallShortcutReceiver" android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
- <intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
生成快捷方式
我们可以在程序启动时直接发送广播创建桌面快捷方式
private void createShortCut(){
Intent intent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//action
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));//快捷方式名字
intent.putExtra("duplicate", false); //是否重复创建快捷方式
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , BatteryProfile.class)); //启动界面
sendBroadcast(intent);//发送广播
}
我们需要在在mainfest.xml加入以下权限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
相关文章推荐
- Android通过应用程序创建快捷方式的方法
- Android基础开发 app快捷方式创建
- ANDROID 桌面快捷方式创建,和判断 返回false问题
- android 创建快捷方式
- Android创建桌面快捷方式几种方法
- 总结:android 创建快捷方式的两种方式+判断是否已经创建+删除快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- android launcher创建删除判断是否存在快捷方式
- Android应用启动后自动创建桌面快捷方式
- android 快捷方式开发(三)通过程序运行时自动创建
- [Android Pro] 创建快捷方式,删除快捷方式,查询是否存在快捷方式
- Android 主界面长按创建快捷方式
- Android创建桌面快捷方式几种方法
- 关于android创建快捷方式会启动两个应用的问题(一)
- android软件创建快捷方式
- Android--创建快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android创建快捷方式
- Android之创建快捷方式
- Android创建和删除桌面快捷方式