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 打游戏通关祝福语简短