Android Utililty Methods Context Get

List of utility methods to do Context Get

Description

The list of methods to do Context Get are organized into topic(s).

Method

StringgetApp(Context ctx, String packageName)
get App
JSONObject json = new JSONObject();
try {
    PackageManager pm = ctx.getPackageManager();
    Intent it = new Intent("android.intent.action.MAIN"); 
    it.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> acts = pm.queryIntentActivities(it, 0);
    int actsSize = acts.size();
    List<ApplicationInfo> allApps = pm.getInstalledApplications(0);
...
StringgetAppKey(Context context)
get App Key
Bundle metaData = null;
String appKey = null;
try {
    ApplicationInfo ai = context.getPackageManager()
            .getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
    if (null != ai)
        metaData = ai.metaData;
...
intgetAppVersion(Context context)
get App Version
try {
    PackageInfo packageInfo = context.getPackageManager()
            .getPackageInfo(context.getPackageName(),
                    PackageManager.PERMISSION_GRANTED);
    return packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
    throw new RuntimeException("Could not get package name: " + e);
ListgetApplicationInfos(Context context)
get Application Infos
PackageManager pManager = context.getApplicationContext()
        .getPackageManager();
return pManager
        .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
intgetApplicationMemoryClass(@Nonnull Context context)
Returns the upper memory usage limit in bytes for the current application retrieved from ActivityManager#getMemoryClass() .
final ActivityManager manager = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
return manager.getMemoryClass() * 1024 * 1024; 
StringgetApplicationMetaData(Context context, String key)
get Application Meta Data
String data = null;
ApplicationInfo info = null;
try {
    info = context.getPackageManager().getApplicationInfo(
            context.getPackageName(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
    e.printStackTrace();
if (info != null && info.metaData != null
        && info.metaData.get(key) != null) {
    data = info.metaData.get(key).toString();
return data;
StringgetApplicationName(Context ctx)
Finds current application name
ApplicationInfo ai;
try {
    Context appContext = ctx.getApplicationContext();
    assert appContext != null;
    final PackageManager pm = appContext.getPackageManager();
    assert pm != null;
    ai = pm.getApplicationInfo(ctx.getPackageName(), 0);
    return (String) (ai != null ? pm.getApplicationLabel(ai)
...
InputStreamgetAsset(@Nonnull Context context, @Nonnull String path)
Returns the InputStream of the given path file using the passed context to retrieve the AssetManager .
AssetManager manager = context.getAssets();
return manager.open(path);
InputStreamgetAsset(@Nonnull Context context, @Nonnull String path)
Returns the InputStream of the given path file using the passed context to retrieve the AssetManager .
return context.getAssets().open(path);
StringgetAuthorityFromPermission(Context context, String permission)
get Authority From Permission
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;