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

StringgetVersionName(Context context)
get Version Name
try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0);
    return pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
    return "unknown";
intgetRawInteger(Context c, int resId)
get Raw Integer
return c.getResources().getInteger(resId);
BitmapgetBitmapFromAssert(Context thisContext, String name)
get Bitmap From Assert
Bitmap bm = null;
try {
    AssetManager am = thisContext.getAssets();
    InputStream is = am.open(name);
    bm = BitmapFactory.decodeStream(is);
    is.close();
} catch (IOException e) {
    e.printStackTrace();
...
StringgetString(Context context, int id)
get String
return context.getResources().getString(id);
StringgetString(Context context, int resId, Map replacement)
get String
String s = context.getString(resId);
s = replaceString(s, replacement);
return s;
StringgetStringFromXml(Context context, int resId)
get String From Xml
return context.getString(resId);
booleangetBoolean(ContentValues alarm, String key)
get Boolean
Integer value = alarm.getAsInteger(key);
return (value != null) && (value != 0);
ContentValuesfindOne(Context context, Uri uri)
find One
if (context == null) {
    Log.e(TAG, "findOne: cannot get context");
    return null;
Cursor cursor = context.getContentResolver().query(uri, null, null,
        null, null);
if (cursor == null || !cursor.moveToFirst()) {
    Log.e(TAG, String.format("findOne: alarm %s not found", uri));
...
StringgetCurrentTimeString(Context aContext, long aDate)
Gets current date in string representation
String pattern = "";
if (DateFormat.is24HourFormat(aContext)) {
    pattern = "dd-MM-yyyy  HH:mm";
} else {
    pattern = "dd-MM-yyyy  hh:mm a";
Calendar calendar = Calendar.getInstance(TimeZone
        .getTimeZone("UTC"));
...
StringgetCurrentTimeString(Context context)
format the time according to the current locale and the user's 12-/24-hour clock preference
return DateFormat.getTimeFormat(context).format(new Date());