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

StringgetSavedPostsPath(Context context)
get Saved Posts Path
String dir = String.format("/Android/data/%s/files/",
        context.getPackageName());
File sd = Environment.getExternalStorageDirectory();
String filePath = sd.getPath() + dir + "savedPosts.txt";
new File(sd.getPath() + dir).mkdirs();
return filePath;
floatgetScaledDensity(Context context)
get Scaled Density
DisplayMetrics dm = context.getResources().getDisplayMetrics();
return dm.scaledDensity;
intgetScenario(Context context, String filename, int widgetid, int defaultScenario)
get Scenario
FileInputStream fis = null;
DataInputStream dis = null;
try {
    fis = context.openFileInput(filename);
    dis = new DataInputStream(fis);
    String line = null;
    do {
        line = dis.readLine();
...
char[]getSeed(Context context)
get Seed
long installed = 0;
try {
    installed = context.getPackageManager().getPackageInfo(
            "edu.uoc.esquelet.app", 0).firstInstallTime;
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
return Long.toString(installed).toCharArray();
...
String[]getSelectedLangCodes(Context context, int[] indexes, boolean[] selectedItems, int codeResourceId)
returns an arrayList of language codes that are active.
ArrayList<String> codes = new ArrayList<String>();
Resources res = context.getResources();
String[] allCodes = res.getStringArray(codeResourceId);
for (int i = 0; i < indexes.length; i++) {
    if (selectedItems[i]) {
        codes.add(allCodes[indexes[i]]);
return codes.toArray(new String[codes.size()]);
StringgetServiceMetaData(Context context, Class serviceClass, String key)
get Service Meta Data
String data = null;
ServiceInfo info = null;
try {
    info = context.getPackageManager().getServiceInfo(
            new ComponentName(context, serviceClass),
            PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
    e.printStackTrace();
...
Signature[]getSignatures(final Context context)
get Signatures
PackageInfo packageInfo = context.getPackageManager()
        .getPackageInfo(getPackageName(context),
                PackageManager.GET_SIGNATURES);
Signature[] signatures = packageInfo.signatures;
return signatures;
StringgetSizeName(Context context)
get Size Name
int screenLayout = context.getResources().getConfiguration().screenLayout;
screenLayout &= Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenLayout) {
case Configuration.SCREENLAYOUT_SIZE_SMALL:
    return "small";
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
    return "normal";
case Configuration.SCREENLAYOUT_SIZE_LARGE:
...
SpannablegetSmiledText(Context context, CharSequence text)
get Smiled Text
Spannable spannable = spannableFactory.newSpannable(text);
addSmiles(context, spannable);
return spannable;
String[]getSmsId(Context context)
get Sms Id
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null,
        null, null);
String[] ids = new String[2];
while (cursor.moveToFirst()) {
    ids[0] = String.valueOf(cursor.getInt(0));
    ids[1] = String.valueOf(cursor.getInt(1));
    break;
...