android桌面添加快捷方式之判断是否存在无效(3)
<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代码
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;
}
作者“TryLoveCatch”
相关新闻>>
- 发表评论
-
- 最新评论 更多>>