http://blog.csdn.net/waylife/article/details/44315103
最近在开发Android桌面快捷方式的时候遇到了一些坑,具体来说就是在某些手机上无法判断已存在的快捷方式,细追了一下发现是ROM系统修改了Android的launcher路径导致无法找到正确的桌面去查找相应的桌面图标。
具体的方法
public booleanhasShortcut(Activity activity,String shortcutName) {
String url ="";
url ="content://"+ getAuthorityFromPermission(activity,"com.android.launcher.permission.READ_SETTINGS") +"/favorites?notify=true";
ContentResolver resolver = activity.getContentResolver();
Cursor cursor = resolver.query(Uri.parse(url), newString[]{"title"},"title=?", newString[]{shortcutName}, null);
if(cursor !=null&& cursor.moveToFirst()) {
cursor.close();
return true;
}
returnhasShortcut2(activity,shortcutName);
}
privateStringgetAuthorityFromPermission(Context context,String permission) {
if(permission ==null)
return null;
List packs = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if(packs !=null) {
for(PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if(providers !=null) {
for(ProviderInfo provider : providers) {
//使用正则去匹配launcher 信息
String valse =".*launcher.*settings$";
Pattern pat = Pattern.compile(valse);
Matcher mat = pat.matcher(provider.authority);
if(mat.find()) {
returnprovider.authority;
}
if(permission.equals(provider.readPermission))
returnprovider.authority;
if(permission.equals(provider.writePermission))
returnprovider.authority;
}
}
}
}
return null;
}
$uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
$uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.android.launcher2.permission.READ_SETTINGS" />
$uses-permission android:name="com.android.launcher2.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
$uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS" />
$uses-permission android:name="org.adw.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="org.adw.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.htc.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.qihoo360.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.qihoo360.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.lge.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.lge.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="net.qihoo.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="net.qihoo.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="org.adwfreak.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="org.adwfreak.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="org.adw.launcher_donut.permission.READ_SETTINGS" />
$uses-permission android:name="org.adw.launcher_donut.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.huawei.launcher3.permission.READ_SETTINGS" />
$uses-permission android:name="com.huawei.launcher3.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.fede.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.fede.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.sec.android.app.twlauncher.settings.READ_SETTINGS" />
$uses-permission android:name="com.sec.android.app.twlauncher.settings.WRITE_SETTINGS" />
$uses-permission android:name="com.anddoes.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.anddoes.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.tencent.qqlauncher.permission.READ_SETTINGS" />
$uses-permission android:name="com.tencent.qqlauncher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.huawei.launcher2.permission.READ_SETTINGS" />
$uses-permission android:name="com.huawei.launcher2.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.android.mylauncher.permission.READ_SETTINGS" />
$uses-permission android:name="com.android.mylauncher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.ebproductions.android.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.ebproductions.android.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
$uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
$uses-permission android:name="telecom.mdesk.permission.READ_SETTINGS" />
$uses-permission android:name="telecom.mdesk.permission.WRITE_SETTINGS" />
$uses-permission android:name="dianxin.permission.ACCESS_LAUNCHER_DATA" />