duanyu47
2015-03-29 13:36:02 +08:00
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 是否添加多个shortcut。false为否,true为是
intent.putExtra("duplicate", false);
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
// 删除的应用程序的ComponentName,即应用程序包名+activity的名字
intent2.setComponent(new ComponentName(this.getPackageName(), this.getPackageName() + ".Main"));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon));
sendBroadcast(intent);
在manifest添加权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />