List of utility methods to do Context Get
String | getPathFromUri(Context context, Uri uri) get Path From Uri String path = null; String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor != null && cursor.getCount() > 0 && cursor.getColumnCount() > 0) { int column_index = -1; try { ... |
CharSequence | getPermissionLabel(Context context, String permission) get Permission Label try { final PackageManager pm = context.getPackageManager(); return pm.getPermissionInfo(permission, 0).loadLabel(pm); } catch (NameNotFoundException e) { return permission; |
SharedPreferences | getPreferences(Context context, String campaignUrn) get Preferences return context.getSharedPreferences(context.getPackageName() + "_" + campaignUrn + "_preferences", Context.MODE_PRIVATE); |
SharedPreferences | getPrefs(Context context) Get preferences object from the context return PreferenceManager.getDefaultSharedPreferences(context);
|
String | getRealPathFromURI(Context context, Uri contentUri) get Real Path From URI String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(contentUri,
proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
...
|
String | getReceiverMetaData(Context context, Class> receiverClass, String key) get Receiver Meta Data String data = null; ActivityInfo info = null; try { info = context.getPackageManager().getReceiverInfo( new ComponentName(context, receiverClass), PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { e.printStackTrace(); ... |
Object | getRequestQueue(Context ctx) get Request Queue Object ret = null; Class networkClass = Class.forName("android.webkit.Network"); if (networkClass != null) { Object networkObj = invokeMethod(networkClass, "getInstance", new Object[] { ctx }, Context.class); if (networkObj != null) { ret = getDeclaredField(networkObj, "mRequestQueue"); return ret; |
int | getResDimen(Context context, int resId) get Res Dimen if (sDimenMap.indexOfKey(resId) > 0) { return sDimenMap.get(resId); } else { int dimen = (int) context.getResources().getDimension(resId); sDimenMap.put(resId, dimen); return dimen; |
String | getResourcesPath(Context context, String url) get Resources Path String dir = String.format("/Android/data/%s/files/", context.getPackageName()); File sd = Environment.getExternalStorageDirectory(); File filePath = new File(sd.getPath() + dir + "savedResources"); filePath.mkdirs(); return filePath + url.substring(url.lastIndexOf("/")); |
String[] | getRevokedPerms(String packageName, Context ctx) get Revoked Perms String[] revokedPerms = null; PackageManager pkgManager = ctx.getPackageManager(); Method getRevokedPermissions; try { getRevokedPermissions = pkgManager.getClass().getMethod( "getRevokedPermissions", java.lang.String.class); Object[] params = new Object[] { packageName }; revokedPerms = (String[]) getRevokedPermissions.invoke( ... |