Example usage for android.content Context getApplicationContext

List of usage examples for android.content Context getApplicationContext

Introduction

In this page you can find the example usage for android.content Context getApplicationContext.

Prototype

public abstract Context getApplicationContext();

Source Link

Document

Return the context of the single, global Application object of the current process.

Usage

From source file:Main.java

public static int getScreenWidth(Context context) {
    new DisplayMetrics();
    return context.getApplicationContext().getResources().getDisplayMetrics().widthPixels;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    new DisplayMetrics();
    return context.getApplicationContext().getResources().getDisplayMetrics().heightPixels;
}

From source file:Main.java

public static void setApplicationContext(Context context) {
    sApplicationContext = context.getApplicationContext();
}

From source file:Main.java

public static String getApplicationVersion(Context context) {
    try {/*from   w  w  w.ja  va2  s.  c om*/
        return context.getApplicationContext().getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        Log.e("NameNotFoundException", e.getMessage());
    }
    return "";
}

From source file:Main.java

public static void remove(Context context, String key) {
    SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();/*from ww w  .  j a v a 2  s.c o m*/
    editor.remove(key);
    editor.commit();
}

From source file:Main.java

public static int[] getScreenSize(Context context) {
    final DisplayMetrics displayMetrics = context.getApplicationContext().getResources().getDisplayMetrics();
    return new int[] { displayMetrics.widthPixels, displayMetrics.heightPixels };
}

From source file:Main.java

public static void showMessage(Context context, String msg) {
    Toast toast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();// www.j  a va  2 s .  com
}

From source file:Main.java

public static void showToast(Context context, String message) {
    Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

/**
 * Wake ups the phone./*from  ww  w .  j  a v a  2 s .c om*/
 * @param context
 */
public static void partialWakeUpLock(Context context) {
    PowerManager pm = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire();
}

From source file:Main.java

/**
 * Gets the current application cache directory path in private storage.
 *
 * @param context Any context./*w ww. jav a  2 s  .c om*/
 * @return The default application cache directory path.
 */
public static String getCacheDirPathName(Context context) {
    return context.getApplicationContext().getCacheDir() + File.separator + getCacheDirName();
}