Android Context Get getAuthorityFromPermission(Context context, String permission)

Here you can find the source of getAuthorityFromPermission(Context context, String permission)

Description

get Authority From Permission

License

Apache License

Declaration

public static final String getAuthorityFromPermission(Context context,
            String permission) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

import android.content.Context;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;

import android.text.TextUtils;

public class Main {
    public static final String getAuthorityFromPermission(Context context,
            String permission) {//from www  .j  a va  2  s .  c  om
        if (TextUtils.isEmpty(permission)) {
            return null;
        }
        List<PackageInfo> packs = context.getPackageManager()
                .getInstalledPackages(PackageManager.GET_PROVIDERS);
        if (packs == null) {
            return null;
        }
        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;
                    }
                }
            }
        }
        return null;
    }
}

Related

  1. getApplicationMemoryClass(@Nonnull Context context)
  2. getApplicationMetaData(Context context, String key)
  3. getApplicationName(Context ctx)
  4. getAsset(@Nonnull Context context, @Nonnull String path)
  5. getAsset(@Nonnull Context context, @Nonnull String path)
  6. getBatteryUsageInfo(Context context)
  7. getBoolean(Context context, String key, boolean defValue)
  8. getBroadcastAddress(Context context)
  9. getCarrier(Context context)