http://blog.csdn.net/waylife/article/details/44315103
最近在開發(fā)Android桌面快捷方式的時(shí)候遇到了一些坑披蕉,具體來(lái)說(shuō)就是在某些手機(jī)上無(wú)法判斷已存在的快捷方式,細(xì)追了一下發(fā)現(xiàn)是ROM系統(tǒng)修改了Android的launcher路徑導(dǎo)致無(wú)法找到正確的桌面去查找相應(yīng)的桌面圖標(biāo)缨称。
具體的方法
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" />