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

DisplayMetricsgetDefaultDisplayMetrics( @Nonnull Context context)
Retrieves the DisplayMetrics for the device's default display.
WindowManager manager = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE));
DisplayMetrics metrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(metrics);
return metrics;
DisplayMetricsgetDefaultDisplayMetrics( @Nonnull Context context)
Retrieves the DisplayMetrics for the device's default display.
WindowManager manager = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
final DisplayMetrics metrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(metrics);
return metrics;
floatgetDensity(Context context)
get Density
final DisplayMetrics dm = context.getResources()
        .getDisplayMetrics();
return dm.density;
floatgetDensity(Context context)
get Density
float scale = context.getResources().getDisplayMetrics().density;
return scale;
intgetDensityDimen(Context context, int dimen)
get Density Dimen
final DisplayMetrics dm = context.getResources()
        .getDisplayMetrics();
return ((int) (dimen * dm.density));
FilegetDiskCacheDir(Context context, String uniqueName)
get Disk Cache Dir
final String cachePath = Environment.MEDIA_MOUNTED
        .equals(Environment.getExternalStorageState()) ? getExternalCacheDir(
        context).getPath()
        : context.getCacheDir().getPath();
return new File(cachePath + File.separator + uniqueName);
DisplayMetricsgetDisplayMetrics(Context context)
get Display Metrics
Resources mResources;
if (context == null) {
    mResources = Resources.getSystem();
} else {
    mResources = context.getResources();
DisplayMetrics mDisplayMetrics = mResources.getDisplayMetrics();
return mDisplayMetrics;
...
byte[]getDisplayPhoto(Context context, long photoFileId)
get Display Photo
Uri displayPhotoUri = ContentUris.withAppendedId(
        DisplayPhoto.CONTENT_URI, photoFileId);
AssetFileDescriptor fd = null;
byte[] photo = null;
try {
    fd = context.getContentResolver().openAssetFileDescriptor(
            displayPhotoUri, "r");
    long len = fd.getLength();
...
floatgetDpiToPix(Context ctx)
Converts 1 dip (device independent pixel) into its equivalent physical pixels
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
        ctx.getResources().getDisplayMetrics());
SharedPreferences.EditorgetEditor( Context ctx)
get Editor
return getDefaultSharedPreferences(ctx).edit();