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

StringgetPathFromUri(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 {
...
CharSequencegetPermissionLabel(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;
SharedPreferencesgetPreferences(Context context, String campaignUrn)
get Preferences
return context.getSharedPreferences(context.getPackageName() + "_"
        + campaignUrn + "_preferences", Context.MODE_PRIVATE);
SharedPreferencesgetPrefs(Context context)
Get preferences object from the context
return PreferenceManager.getDefaultSharedPreferences(context);
StringgetRealPathFromURI(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();
...
StringgetReceiverMetaData(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();
...
ObjectgetRequestQueue(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;
intgetResDimen(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;
StringgetResourcesPath(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(
...