public static void addIcon(Context context){
if(hasShortCut(context)){
return;
}
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
intent.putExtra("duplicate", false);
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
intent2.setComponent(new ComponentName(context.getPackageName(), context.getPackageName() + ".LoginActivity"));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context,
R.drawable.ic_launcher));
context.sendBroadcast(intent);
}
需要权限 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Android 自动添加桌面图标
最新推荐文章于 2023-12-28 17:34:47 发布