閱讀524 返回首頁    go 阿裏雲 go 技術社區[雲棲]


使用程序創建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

  上一篇:go C# 開機隨係統啟動
  下一篇:go eclipse + cdt + gdb 進行arm linux 交叉調試 (