Android中创建快捷方式代码实例
1、添加权限(必须)
<uses-permissionandroid:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
2、添加快捷键
publicstaticvoidsetupShortcut(Activityactivity)
{
IntentshortcutIntent=newIntent(activity,MainActivity.class);//启动首页(launcherActivity)
Intentintent=newIntent("com.android.launcher.action.INSTALL_SHORTCUT"); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"hello");//快捷键名字可以任意,不过最好为app名称 ParcelableiconResource=Intent.ShortcutIconResource.fromContext(activity,R.drawable.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource); intent.putExtra("duplicate",false);//不允许重复创建
activity.sendBroadcast(intent);//发送广播创建快捷键 }
热门推荐
10 爱情贺卡祝福语简短英语
11 娃娃考试祝福语幽默简短
12 结婚祝福语简短精辟 兄弟
13 表达朋友的祝福语简短
14 春节感恩祝福语简短的
15 结婚祝福语粤语大全简短
16 恭喜朋友升职祝福语简短
17 圣诞饭店祝福语大全简短
18 建工系毕业祝福语简短