List of utility methods to do Context Get
String | getApp(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); ... |
String | getAppKey(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; ... |
int | getAppVersion(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); |
List | getApplicationInfos(Context context) get Application Infos PackageManager pManager = context.getApplicationContext()
.getPackageManager();
return pManager
.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
|
int | getApplicationMemoryClass(@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; |
String | getApplicationMetaData(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; |
String | getApplicationName(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) ... |
InputStream | getAsset(@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);
|
InputStream | getAsset(@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);
|
String | getAuthorityFromPermission(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; |