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 教师闺蜜祝福语简短