Intent shortcutintent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重复创建
shortcutintent.putExtra("duplicate", false);
// 需要实现的名称
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
act.getString(appnameResId));
// 快捷图片
Parcelable icon = Intent.ShortcutIconResource.fromContext(
act.getApplicationContext(), iconResId);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 点击快捷图片,运行的程序主入口
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(act.getApplicationContext(), act.getClass()).setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));// 发送广播
act.sendBroadcast(shortcutintent);注意:如果没有红色部分,每次点击快捷方式都会重新启动app,无论当前app是否运行。
创建app快捷方式
最新推荐文章于 2021-05-28 02:04:46 发布