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

StringgetExternalCacheDir(Context context)
get External Cache Dir
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
    File f1 = context.getExternalCacheDir();
    if (f1 != null) {
        return f1.getPath();
    } else {
        return null;
} else {
...
FilegetExternalCacheDir(Context context)
get External Cache Dir
final String cacheDir = "/Android/data/" + context.getPackageName()
        + "/cache/";
return new File(Environment.getExternalStorageDirectory().getPath()
        + cacheDir);
FilegetExternalCacheDir(Context context)
get External Cache Dir
if (hasExternalCacheDir()) {
    return context.getExternalCacheDir();
final String cacheDir = "/Android/data/" + context.getPackageName()
        + "/cache/";
return new File(Environment.getExternalStorageDirectory().getPath()
        + cacheDir);
TypefacegetFAFont(Context context)
get FA Font
Typeface tf = Typeface.createFromAsset(context.getAssets(),
        font_awesome);
return tf;
ListgetFiles(Context context, String ext)
get Files
File dir = context.getFilesDir();
final List<File> files = new ArrayList<File>();
File[] subFiles = dir.listFiles();
if (subFiles != null) {
    for (File file : subFiles) {
        if (file.isFile() && file.getName().endsWith(ext)) {
            files.add(file);
return files;
StringgetFromAssets(Context con, String fileName)
get From Assets
String result = "";
try {
    InputStream in = con.getResources().getAssets().open(fileName);
    int lenght = in.available();
    byte[] buffer = new byte[lenght];
    in.read(buffer);
    result = EncodingUtils.getString(buffer, "UTF-8");
} catch (Exception e) {
...
UrigetHelpUrl(Context context, String s)
get Help Url
if (TextUtils.isEmpty(s))
    throw new IllegalArgumentException(
            "getHelpUrl(): fromWhere must be non-empty");
String s1 = "http://www.google.com/support/mobile/?hl=%locale%";
if (s1.contains("%locale%")) {
    Locale locale = Locale.getDefault();
    s1 = s1.replace(
            "%locale%",
...
StringgetImei(Context context, String imei)
get Imei
TelephonyManager telephonyManager = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
imei = telephonyManager.getDeviceId();
return imei;
ListgetInstalleApps(Context mContext)
get Installe Apps
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
return mContext.getPackageManager().queryIntentActivities(
        mainIntent, 0);
LayoutInflatergetInstance(Context context)
get Instance
if (mInstance == null)
    mInstance = LayoutInflater.from(context);
return mInstance;