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

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

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

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

/**
* 為程序創(chuàng)建桌面快捷方式 ,這樣寫,在程序卸載的時候,快捷方式也會一并刪除
*/
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); // 不允許重復創(chuàng)建
    /*
     * 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);
}
//判斷是否已經創(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;
}

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

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

相關文章

  • WindowManagerService服務是如何以堆棧的形式來組織窗口

    WindowManagerService服務是如何以堆棧的形式來組織窗口

    我們知道,在Android系統中,Activity是以堆棧的形式組織在ActivityManagerService服務中的;在本文中,我們就詳細分析WindowManagerService服務是如何以堆棧的形式來組織窗口的
    2013-01-01
  • 關于AndroidStudio新建與編譯項目速度慢解決辦法

    關于AndroidStudio新建與編譯項目速度慢解決辦法

    這篇文章主要介紹了關于AndroidStudio新建與編譯項目速度慢的解決辦法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • Android實現加載等待展示

    Android實現加載等待展示

    這篇文章主要為大家詳細介紹了Android實現加載等待展示,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android入門之IntentService的使用教程詳解

    Android入門之IntentService的使用教程詳解

    IntentService的生命周期中有一個非常好的方法-onHandleIntent方法,它是一個abstract方法,開發(fā)者在實現IntentService時可以覆蓋它來處理“長事務”。本文就來聊聊IntentService的使用,需要的可以參考一下
    2022-12-12
  • 基于Flutter實現多邊形和多角星組件

    基于Flutter實現多邊形和多角星組件

    開發(fā)中,免不了會用到多邊形、多角星等圖案,比較常用的多邊形比如雷達圖、多角星比如評價星級的五角星等,本文章就使用Flutter繪制封裝一個這樣的組件,需要的可以參考一下
    2022-05-05
  • Android獲取apk簽名指紋的md5值(防止重新被打包)的實現方法

    Android獲取apk簽名指紋的md5值(防止重新被打包)的實現方法

    這篇文章主要介紹了Android獲取apk簽名指紋的md5值以防止重新被打包的實現方法,結合實例形式詳細分析了Android獲取apk md5值的常用技巧,需要的朋友可以參考下
    2016-07-07
  • android nfc常用標簽讀取總結

    android nfc常用標簽讀取總結

    NFC(Near Field Communication,近場通信)是一種數據傳輸技術這篇文章主要介紹了android nfc常用標簽讀取總結,有興趣的可以了解一下。
    2016-12-12
  • Android Service判斷設備聯網狀態(tài)詳解

    Android Service判斷設備聯網狀態(tài)詳解

    本文主要介紹Android Service判斷聯網狀態(tài),這里提供了相關資料并附有示例代碼,有興趣的小伙伴可以參考下,幫助開發(fā)相關應用功能
    2016-08-08
  • Android實現拍照和錄制視頻功能

    Android實現拍照和錄制視頻功能

    這篇文章主要為大家詳細介紹了Android實現拍照和錄制視頻功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android打開圖庫選擇照片功能代碼

    Android打開圖庫選擇照片功能代碼

    這篇文章主要介紹了Android打開圖庫選擇照片功能代碼以及實現流程分析,對此有需要的朋友參考學習下吧。
    2018-02-02

最新評論