Android examples for App:Manifest
default permission is "com.android.launcher.permission.READ_SETTINGS"
//package com.java2s; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.text.TextUtils; import java.util.List; public class Main { private static String mBufferedValue = null; /**/*from w ww. j av a 2s. c om*/ * default permission is "com.android.launcher.permission.READ_SETTINGS"<br/> * {@link #getAuthorityFromPermission(Context, String)}<br/> * * @param context context */ public static String getAuthorityFromPermissionDefault(Context context) { if (TextUtils.isEmpty(mBufferedValue))//we get value buffered mBufferedValue = getAuthorityFromPermission(context, "com.android.launcher.permission.READ_SETTINGS"); return mBufferedValue; } public static String getAuthorityFromPermission(Context context, String permission) { if (TextUtils.isEmpty(permission)) { return ""; } try { List<PackageInfo> packs = context.getPackageManager() .getInstalledPackages(PackageManager.GET_PROVIDERS); if (packs == null) { return ""; } for (PackageInfo pack : packs) { ProviderInfo[] providers = pack.providers; if (providers != null) { for (ProviderInfo provider : providers) { if (permission.equals(provider.readPermission) || permission .equals(provider.writePermission)) { return provider.authority; } } } } } catch (Exception e) { e.printStackTrace(); } return ""; } }