清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
public static boolean isAddShortCut(Context context) {
boolean isInstallShortcut = false;
final ContentResolver cr = context.getContentResolver();
String AUTHORITY = getAuthorityFromPermission(context, "com.android.launcher.permission.READ_SETTINGS");
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
Cursor c = cr.query(CONTENT_URI, new String[] {"title"}, "title=?", new String[] {context.getString(R.string.app_name)}, null);
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
if (c != null) {
c.close();
}
return isInstallShortcut;
}
public static String getAuthorityFromPermission(Context context, String permission) {
if (TextUtils.isEmpty(permission)) {
return null;
}
List<PackageInfo> packInfos = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if (packInfos == null) {
return null;
}
for (PackageInfo info : packInfos) {
ProviderInfo[] providers = info.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
if (permission.equals(provider.readPermission) || permission.equals(provider.writePermission)) {
return provider.authority;
}
}
}
}
return null;
}
boolean isInstallShortcut = false;
final ContentResolver cr = context.getContentResolver();
String AUTHORITY = getAuthorityFromPermission(context, "com.android.launcher.permission.READ_SETTINGS");
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
Cursor c = cr.query(CONTENT_URI, new String[] {"title"}, "title=?", new String[] {context.getString(R.string.app_name)}, null);
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
if (c != null) {
c.close();
}
return isInstallShortcut;
}
public static String getAuthorityFromPermission(Context context, String permission) {
if (TextUtils.isEmpty(permission)) {
return null;
}
List<PackageInfo> packInfos = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if (packInfos == null) {
return null;
}
for (PackageInfo info : packInfos) {
ProviderInfo[] providers = info.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
if (permission.equals(provider.readPermission) || permission.equals(provider.writePermission)) {
return provider.authority;
}
}
}
}
return null;
}