Android 自动添加桌面图标
来源:互联网 发布:玩客币交易网站源码 编辑:程序博客网 时间:2024/04/27 03:02
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"/>