Intent addShortCut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 加載app名
String title = getResources().getString(R.string.app_name);
// 加載app的logo
Parcelable icon = Intent.ShortcutIconResource.fromContext(
ShortCutsActivity.this, R.drawable.ic_launcher);
//點擊快捷方式後操作Intent,快捷方式建立後,再次啓動該程序
Intent intent = new Intent(ShortCutsActivity.this, ShortCutsActivity.class);
//設置快捷方式的標題
addShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
//設置快捷方式的圖標
addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//設置快捷方式對應的Intent
addShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
//發送廣播添加快捷方式
sendBroadcast(addShortCut);
權限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />