524
技術社區[雲棲]
使用程序創建Android桌麵快捷方式
下麵是使用程序創建Android桌麵快捷方式的實例代碼:
public static void addShortcut(Context context) {
String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
// 快捷方式要啟動的包
Intent intent = gotoWhere(context);
// 設置快捷方式的參數
Intent shortcutIntent = new Intent(ACTION_INSTALL_SHORTCUT);
// 設置名稱
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(R.string.wap)); // 設置啟動 Intent
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
// 設置圖標
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,R.drawable.icon));
// 隻創建一次快捷方式
shortcutIntent.putExtra("duplicate", false);
// 創建
context.sendBroadcast(shortcutIntent);
}
最後更新:2017-04-02 17:51:23