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

Android添加(創(chuàng)建)、刪除及判斷是否存在桌面快捷方式的方法

 更新時間:2015年05月21日 10:12:01   作者:3H  
這篇文章主要介紹了Android添加(創(chuàng)建)、刪除及判斷是否存在桌面快捷方式的方法,涉及Android針對桌面快捷方式的相關操作技巧,需要的朋友可以參考下

本文實例講述了Android添加(創(chuàng)建)、刪除及判斷是否存在桌面快捷方式的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

/**
* 判斷桌面是否已添加快捷方式
* 
* @param cx
* @param titleName
* 快捷方式名稱
* @return
*/
public static boolean hasShortcut(Context cx) {
boolean result = false;
// 獲取當前應用名稱
String title = null;
try {
final PackageManager pm = cx.getPackageManager();
title = pm.getApplicationLabel(
pm.getApplicationInfo(cx.getPackageName(),
PackageManager.GET_META_DATA)).toString();
} catch (Exception e) {
}
final String uriStr;
if (android.os.Build.VERSION.SDK_INT < 8) {
uriStr = "content://com.android.launcher.settings/favorites?notify=true";
} else {
uriStr = "content://com.android.launcher2.settings/favorites?notify=true";
}
final Uri CONTENT_URI = Uri.parse(uriStr);
final Cursor c = cx.getContentResolver().query(CONTENT_URI, null,
"title=?", new String[] { title }, null);
if (c != null && c.getCount() > 0) {
result = true;
}
return result;
}
/**
* 刪除當前應用的桌面快捷方式
* 
* @param cx
*/
public static void delShortcut(Context cx) {
Intent shortcut = new Intent(
"com.android.launcher.action.UNINSTALL_SHORTCUT");
// 獲取當前應用名稱
String title = null;
try {
final PackageManager pm = cx.getPackageManager();
title = pm.getApplicationLabel(
pm.getApplicationInfo(cx.getPackageName(),
PackageManager.GET_META_DATA)).toString();
Log.v("test", "title:" + title);
} catch (Exception e) {
}
// 快捷方式名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
Intent shortcutIntent = cx.getPackageManager()
.getLaunchIntentForPackage(cx.getPackageName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
cx.sendBroadcast(shortcut);
}
/**
* 為當前應用添加桌面快捷方式
* 
* @param cx
* @param appName
* 快捷方式名稱
*/
public static void addShortcut(Context cx) {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
Intent shortcutIntent = cx.getPackageManager()
.getLaunchIntentForPackage(cx.getPackageName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// 獲取當前應用名稱
String title = null;
try {
final PackageManager pm = cx.getPackageManager();
title = pm.getApplicationLabel(
pm.getApplicationInfo(cx.getPackageName(),
PackageManager.GET_META_DATA)).toString();
Log.v("test", "title:" + title);
} catch (Exception e) {
}
// 快捷方式名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 不允許重復創(chuàng)建(不一定有效)
shortcut.putExtra("duplicate", false);
// 快捷方式的圖標
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(cx, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
cx.sendBroadcast(shortcut);
}

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

相關文章

  • 詳解如何從原生Android 跳轉到hbuilder項目

    詳解如何從原生Android 跳轉到hbuilder項目

    這篇文章主要介紹了從原生Android 跳轉到hbuilder項目,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • Android編程實現(xiàn)圖片的瀏覽、縮放、拖動和自動居中效果

    Android編程實現(xiàn)圖片的瀏覽、縮放、拖動和自動居中效果

    這篇文章主要介紹了Android編程實現(xiàn)圖片的瀏覽、縮放、拖動和自動居中效果,以具體實例形式分析了Android針對圖片各種常見顯示效果的布局及功能實現(xiàn)技巧,需要的朋友可以參考下
    2015-11-11
  • Kotlin Thread線程與UI更新詳解

    Kotlin Thread線程與UI更新詳解

    本篇主要介紹Kotlin中Thread線程與UI更新,注意不是協(xié)程而是線程。Kotlin本身是支持線程的。同時協(xié)程也是運行在線程中的
    2022-12-12
  • Android使用ContentResolver搜索手機通訊錄的方法

    Android使用ContentResolver搜索手機通訊錄的方法

    這篇文章主要介紹了Android使用ContentResolver搜索手機通訊錄的方法,結合實例形式分析了Android中ContentResolver操作手機通訊錄的具體步驟與相關實現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • android設置adb自帶screenrecord錄屏命令

    android設置adb自帶screenrecord錄屏命令

    這篇文章主要介紹了android設置adb自帶screenrecord錄屏命令,需要的朋友可以參考下
    2018-11-11
  • Android6.0動態(tài)申請權限所遇到的問題小結

    Android6.0動態(tài)申請權限所遇到的問題小結

    這篇文章給大家介紹了Android6.0動態(tài)申請權限所遇到的問題,在沒給大家介紹這下問題之前,先給大家說下基本定義和基本使用方式,本文給大家介紹的非常詳細,具有參考借鑒價值,對android 6.0 動態(tài)權限遇到問題感興趣的朋友一起看看吧
    2016-11-11
  • Android 防止多次重復點擊的三種方法的示例

    Android 防止多次重復點擊的三種方法的示例

    本篇文章主要介紹了Android 防止多次重復點擊的三種方法的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • Android 多線程的實現(xiàn)方法總結

    Android 多線程的實現(xiàn)方法總結

    這篇文章主要介紹了Android 多線程的實現(xiàn)方法總結的相關資料,這里提供三種方法,幫助大家掌握這部分內容,需要的朋友可以參考下
    2017-08-08
  • Android ViewFlipper的詳解及實例

    Android ViewFlipper的詳解及實例

    這篇文章主要介紹了Android ViewFlipper的詳解及實例的相關資料,通過本文希望能幫助大家理解這部分內容,需要的朋友可以參考下
    2017-08-08
  • 老生常談ProgressBar、ProgessDialog的用法

    老生常談ProgressBar、ProgessDialog的用法

    下面小編就為大家?guī)硪黄仙U凱rogressBar、ProgessDialog的用法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07

最新評論