国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現創建,刪除,判斷快捷方式的方法

2019-10-23 19:45:32
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現創建,刪除,判斷快捷方式的方法。分享給大家供大家參考,具體如下:

/*** 為程序創建桌面快捷方式 ,這樣寫,在程序卸載的時候,快捷方式也會一并刪除*/private void addShortcut() {    Intent shortcutIntent = new Intent(        "com.android.launcher.action.INSTALL_SHORTCUT");    // 快捷方式的名稱    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,        getString(R.string.app_name));    shortcutIntent.putExtra("duplicate", false); // 不允許重復創建    /*     * shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(     * getApplicationContext(), SplashActivity.class));     */    // 注意: ComponentName的第二個參數必須加上點號(.),否則快捷方式無法啟動相應程序    ComponentName comp = new ComponentName(this.getPackageName(),        this.getPackageName() + "." + this.getLocalClassName());    Intent intent = new Intent(Intent.ACTION_MAIN);    intent.setAction("android.intent.action.MAIN");    intent.addCategory("android.intent.category.LAUNCHER");    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,        intent.setComponent(comp));    // 快捷方式的圖標    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(        this, R.drawable.icon_launcher);    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);    sendBroadcast(shortcutIntent);}//判斷是否已經創建快捷方式private boolean hasShortcut() {    boolean isInstallShortcut = false;    final ContentResolver resolver = this.getContentResolver();    final String AUTHORITY;    if (android.os.Build.VERSION.SDK_INT < 8) {      AUTHORITY = "com.android.launcher.settings";    } else {      AUTHORITY = "com.android.launcher2.settings";    }    final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY        + "/favorites?notify=true");    Cursor c = resolver        .query(CONTENT_URI,            new String[] { "title", "iconResource" },            "title=?",            new String[] { this.getString(R.string.app_name).trim() },            null);    if (c != null && c.getCount() > 0) {      isInstallShortcut = true;    }    return isInstallShortcut;}

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汾西县| 安溪县| 布尔津县| 洮南市| 苍南县| 枣庄市| 江山市| 团风县| 垦利县| 宁陕县| 新巴尔虎左旗| 昭通市| 福贡县| 同江市| 铜山县| 额尔古纳市| 安新县| 九龙坡区| 合作市| 光山县| 阿拉善盟| 兴仁县| 方正县| 凤翔县| 确山县| 沧源| 横峰县| 登封市| 揭东县| 昭通市| 华坪县| 大姚县| 竹溪县| 寿光市| 徐州市| 聂荣县| 青河县| 南丰县| 北碚区| 城固县| 河池市|