Java tutorial
//package com.java2s; import java.util.List; import android.app.Activity; import android.content.ContentResolver; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; import android.widget.Toast; public class Main { public static void getAuthorityFromPermission(Activity context) { String read_settings = "com.android.launcher.permission.READ_SETTINGS"; String write_settings = "com.android.launcher.permission.WRITE_SETTINGS"; List<PackageInfo> 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) { if ((read_settings.equals(provider.readPermission) || (write_settings.equals(provider.writePermission)))) { Toast.makeText(context, pack.applicationInfo.packageName, Toast.LENGTH_LONG).show(); if (isExistShortcut(context, provider.authority)) { continue; } else { /* * ShotcutUtil.createShortcut(context, SplashActivity.class, * R.string.app_name, R.drawable.icon, false); */ continue; } } } } } } return; } public static boolean isExistShortcut(Activity context, String authorities) { boolean isInstallShortcut = false; final ContentResolver cr = context.getContentResolver(); /* * if (android.os.Build.VERSION.SDK_INT < 8) { AUTHORITIES = * "com.android.launcher.settings"; } else { AUTHORITIES = * "com.android.launcher2.settings"; } */ final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?", new String[] { context.getApplication().getPackageName() }, null); if (c != null) { if (c.getCount() > 0) { isInstallShortcut = true; } c.close(); } return isInstallShortcut; } }