最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

/**
* 判斷桌面是否已添加快捷方式
* 
* @param cx
* @param titleName
* 快捷方式名稱
* @return
*/
public static boolean hasShortcut(Context cx) {
boolean result = false;
// 獲取當前應(yīng)用名稱
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;
}
/**
* 刪除當前應(yīng)用的桌面快捷方式
* 
* @param cx
*/
public static void delShortcut(Context cx) {
Intent shortcut = new Intent(
"com.android.launcher.action.UNINSTALL_SHORTCUT");
// 獲取當前應(yīng)用名稱
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);
}
/**
* 為當前應(yīng)用添加桌面快捷方式
* 
* @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);
// 獲取當前應(yīng)用名稱
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);
// 不允許重復(fù)創(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程序設(shè)計有所幫助。

相關(guān)文章

最新評論

穆棱市| 卓资县| 论坛| 抚宁县| 罗田县| 华坪县| 永新县| 南川市| 南平市| 南陵县| 梁山县| 绥棱县| 南丰县| 遂昌县| 台湾省| 安塞县| 军事| 周口市| 永定县| 沧源| 姚安县| 沂源县| 谢通门县| 小金县| 达拉特旗| 同德县| 高州市| 和硕县| 黔江区| 中卫市| 平定县| 乐平市| 广安市| 镇原县| 海门市| 石城县| 徐闻县| 湖口县| 右玉县| 华池县| 红原县|