美文网首页
Android 快捷启动图标

Android 快捷启动图标

作者: ff_hh | 来源:发表于2017-10-24 17:03 被阅读0次

核心代码

Intent shortcut =newIntent("com.android.launcher.action.INSTALL_SHORTCUT");

//不允许重复创建

shortcut.putExtra("duplicate",false)

//需要实现的名称

shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, strName);

//快捷图片

Parcelable icon = Intent.ShortcutIconResource.formContext(context, iconResId);

shortcut.putExtra(Intent.EXTRA_SHORTCUT_RESOURCE, icon);

//点击快捷图片,运行程序

Intent intent =newIntent(context.getApplicationContext(),MainActivity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//Android启动模式 清除当前activity main 及以上的 activity 并从新创建 MainActivity;

shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

需要注意

被启动的 activity 必须是默认启动的ac

默认启动的标签 ,否则会提示该应未安装 或者 app isn’t installed

相关文章

网友评论

      本文标题:Android 快捷启动图标

      本文链接:https://www.haomeiwen.com/subject/yorxpxtx.html