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 送给学长毕业祝福语简短