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

首頁 > 系統 > Android > 正文

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

2019-12-12 03:37:38
字體:
來源:轉載
供稿:網友

本文實例講述了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開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 茶陵县| 香港| 且末县| 曲麻莱县| 五常市| 巴南区| 沂水县| 平泉县| 荆州市| 平乐县| 乐陵市| 镶黄旗| 奇台县| 临猗县| 永康市| 广西| 焦作市| 永平县| 南陵县| 乡城县| 肥东县| 伊春市| 梅河口市| 泊头市| 彭阳县| 兰坪| 长沙市| 晋城| 溆浦县| 滨州市| 两当县| 临邑县| 融水| 额济纳旗| 南阳市| 株洲县| 海阳市| 宁德市| 浦城县| 福贡县| 汝州市|