创建app快捷方式

  • Post author:
  • Post category:其他


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是否运行。



版权声明:本文为ZHXLXH原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。