转载:http://blog.csdn.net/luck_apple/article/details/7173104
首先需要权限:
- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
- Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
- ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); //图标
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); //名称
- intent.putExtra("duplicate", false);
- Intent sIntent = new Intent(Intent.ACTION_MAIN);
- sIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- sIntent.setClass(this, MainActivity.class);
- intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sIntent);
- sendBroadcast(intent);