欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法

 更新時(shí)間:2017年02月24日 12:01:07   作者:Jacob-wj  
這篇文章主要介紹了Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法,結(jié)合實(shí)例形式分析了Android編程針對(duì)快捷方式的常用操作技巧,需要的朋友可以參考下

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

/**
* 為程序創(chuàng)建桌面快捷方式 ,這樣寫(xiě),在程序卸載的時(shí)候,快捷方式也會(huì)一并刪除
*/
private void addShortcut() {
    Intent shortcutIntent = new Intent(
        "com.android.launcher.action.INSTALL_SHORTCUT");
    // 快捷方式的名稱(chēng)
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
        getString(R.string.app_name));
    shortcutIntent.putExtra("duplicate", false); // 不允許重復(fù)創(chuàng)建
    /*
     * shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
     * getApplicationContext(), SplashActivity.class));
     */
    // 注意: ComponentName的第二個(gè)參數(shù)必須加上點(diǎn)號(hào)(.),否則快捷方式無(wú)法啟動(dòng)相應(yīng)程序
    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));
    // 快捷方式的圖標(biāo)
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
        this, R.drawable.icon_launcher);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    sendBroadcast(shortcutIntent);
}
//判斷是否已經(jīng)創(chuàng)建快捷方式
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;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論