List of utility methods to do Context Get
void | readRaw(Context ctx, int res_id) Method to read in a text file placed in the res/raw directory of the application. InputStream is = ctx.getResources().openRawResource(res_id); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr, 8192); try { String test; while (true) { test = br.readLine(); if (test == null) ... |
Drawable | loadImageFromAsset(Context context, String id) load Image From Asset try { Resources resources = context.getResources(); AssetManager am = resources.getAssets(); InputStream ims = am.open(id + ".png"); Drawable d = Drawable.createFromStream(ims, null); return d; } catch (IOException ex) { return null; ... |
boolean | hasTelephony(@Nonnull Context context) Checks if the device has the PackageManager#FEATURE_TELEPHONY . final PackageManager manager = context.getPackageManager(); return manager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); |
String | getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) Get the value of the data column for this Uri. Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor ... |
String | getPath(final Context context, final Uri uri) Get a file path from a Uri. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (DocumentsContract.isDocumentUri(context, uri)) { if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract .getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { ... |
String | cachedJson(Context context, URI uri) cached Json try { StringBuffer json = new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader( context.openFileInput(String.format("%d.json", uri.hashCode())))); String line = null; while ((line = in.readLine()) != null) { json.append(line); ... |
void | cacheJson(Context context, URI uri, String jsonSource) cache Json try { PrintWriter out = new PrintWriter(context.openFileOutput( String.format("%d.json", uri.hashCode()), Context.MODE_PRIVATE)); out.write(jsonSource); out.close(); } catch (IOException ex) { Log.e(TAG, String.format("error caching %s", uri)); ... |
SharedPreferences | getSharedPreferences(Context context) get Shared Preferences return PreferenceManager.getDefaultSharedPreferences(context);
|
File | getAndroidDBDir(Context context) get Android DB Dir return new File(Environment.getDataDirectory(), "//data//" + context.getPackageName() + "//databases//"); |
int | getAnimId(Context paramContext, String paramString) get Anim Id return paramContext.getResources().getIdentifier(paramString, "anim", paramContext.getPackageName()); |