private void createShortCut() {
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// 设置快捷方式名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 设置快捷方式图标
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
// 防止重复创建
intent.putExtra("duplicate", false);
sendBroadcast(intent);
}android安卓创建快捷方式
创建应用快捷方式
最新推荐文章于 2024-06-24 18:19:34 发布
本文将指导您如何在Android应用中创建快捷方式,包括设置快捷方式的名称、图标、权限及发送广播实现快捷方式的安装。
2354

被折叠的 条评论
为什么被折叠?



