1:權限
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
2:代碼
/**
* 創建桌面快捷方式
*/
public void createShut() {
// 創建添加快捷方式的Intent
Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
String title = getResources().getString(R.string.app_name);
// 加載快捷方式的圖標
Parcelable icon = Intent.ShortcutIconResource.fromContext(Appstart.this, R.drawable.ic_launcher);
// 創建點擊快捷方式後操作Intent,該處當點擊創建的快捷方式後,再次啓動該程序
Intent myIntent = new Intent(Appstart.this,Appstart.class);
// 設置快捷方式的標題
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 設置快捷方式的圖標
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 設置快捷方式對應的Intent
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 發送廣播添加快捷方式
sendBroadcast(addIntent);
}