//設置快捷方式要跳轉的activity
Intent intent = new Intent();
intent.setClass(this, SplashActivity.class);
//要加上下面兩句,否則應用被卸載之後,快捷方式不會消失
// intent.setAction("android.intent.action.MAIN");
// intent.addCategory("android.intent.category.LAUNCHER");
Intent addShortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
Parcelable icon = Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon);//快捷方式圖標
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));//設置名稱
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);//點擊快捷方式後執行的操作
addShortcut.putExtra("duplicate", false);//是否允許快捷方式重複
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
sendBroadcast(addShortcut);