android桌面添加快捷方式之判断是否存在无效
来源:互联网 发布:郝斌c语言180视频教程 编辑:程序博客网 时间:2024/05/19 13:22
Android桌面程序提供了应用添加和删除桌面快捷方式的功能以及判断快捷方式是否存在,只要传入快捷方式标题、图标及点击快捷方式执行的应用Intent即可
在launcher.db中favortes这个表中会保存快捷方式的相关数据,但是判断快捷方式的方法不是总是很有效 上网查了下 发现大家的为问题都是2.2版本之后的就判断不正确了,在此 将原来的判断方法贴一下
Java代码
private boolean hasShortCut() {
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(Uri.parse("content://com.android.launcher.settings/favorites?notify=true"), null, "title=?",
new String[] {getString(R.string.app_name)}, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}后来 我看了一下2.2版本和1.5版本的launcher中的清单文件
1.5的如下:
Java代码
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name=".InstallShortcutReceiver"
android:permission="com.lp.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.lp.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name=".UninstallShortcutReceiver"
android:permission="com.lp.launcher.permission.UNINSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.lp.launcher.action.UNINSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- The settings provider contains Home's data, like the workspace favorites -->
<provider
android:name="LauncherProvider"
android:authorities="com.lp.launcher.settings"
android:writePermission="com.lp.launcher.permission.WRITE_SETTINGS"
android:readPermission="com.lp.launcher.permission.READ_SETTINGS" />
2.2的如下:
Java代码
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.InstallShortcutReceiver"
android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- Intent received used to uninstall shortcuts from other applications -->
<receiver
android:name="com.android.launcher2.UninstallShortcutReceiver"
android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
<intent-filter>
<action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
</intent-filter>
</receiver>
<!-- The settings provider contains Home's data, like the workspace favorites -->
<provider
android:name="com.android.launcher2.LauncherProvider"
android:authorities="com.android.launcher2.settings"
android:writePermission="com.android.launcher.permission.WRITE_SETTINGS"
android:readPermission="com.android.launcher.permission.READ_SETTINGS" />
可以看出来 创建和删除快捷方式的receiver没什么变化
但是查询的provider有了变化Java代码
android:authorities="com.android.launcher.settings"Java代码
android:authorities="com.android.launcher2.settings"
所以说我们的方法用在2.2之后的版本是无效的现修改代码如下:
Java代码
OK,这样就可以兼容SDK版本了!
public static boolean hasShortCut(Context context) {
String url = "";
System.out.println(getSystemVersion());
if(getSystemVersion() < 8){
url = "content://com.android.launcher.settings/favorites?notify=true";
}else{
url = "content://com.android.launcher2.settings/favorites?notify=true";
}
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(Uri.parse(url), null, "title=?",
new String[] {context.getString(R.string.app_name)}, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
private static int getSystemVersion(){
return android.os.Build.VERSION.SDK_INT;
}
- android桌面添加快捷方式之判断是否存在无效
- android桌面添加快捷方式之判断是否存在无效
- Android判断桌面快捷方式是否存在!
- android 判断桌面快捷方式是否存在
- Android判断桌面快捷方式是否存在
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- 如何判断桌面快捷方式是否存在
- Android判断快捷方式是否存在
- Android应用程序快捷方式操作(添加,删除,判断是否存在)
- Android创建桌面快捷方式和判断当前快捷方式是否已经存在
- android查看桌面快捷方式是否存在
- 查询Android桌面快捷方式是否存在
- android 创建、删除、判断是否存在快捷方式
- android 快捷方式开发(一)判断是否存在快捷方式
- 【编程珠玑】第十三章 搜索
- (补)第十二周实验报告(4)
- ubuntu 12.04下安装eclipse-jee-indigo-SR2
- Android 如何通过长按list弹出操作选项
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- android桌面添加快捷方式之判断是否存在无效
- Magento付款流程的简化【7】
- delphi+sqlserver 换行
- 苹果千万代言把公众给hold住了
- Android开发之windows系统上NDK的安装与使用
- Android下如何卸载和格式化sdcard
- jquery+autocomplete+json 操作
- 数据库的基本概念
- 数据结构在实际开发过程中的应用