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 String getDeviceId(Context context) {
    String deviceId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),
            Settings.Secure.ANDROID_ID);
    return deviceId;
}

From source file:Main.java

/**
 * Method setBackgroundImage//  w w  w .  j  a  v a2 s .c om
 */
public static void setBackgroundImage(Context context, View view, int resId) {
    InputStream inStream = context.getApplicationContext().getResources().openRawResource(resId);
    BitmapDrawable drawable = new BitmapDrawable(inStream);
    view.setBackgroundDrawable(drawable);
}

From source file:Main.java

public static void putFloat(Context context, String key, float value) {
    SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();/*  www.  j av  a 2  s .  com*/
    editor.putFloat(key, value);
    editor.commit();
}

From source file:Main.java

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

From source file:Main.java

private static String[] getExternalDirs(Context context) {
    Context mContext = context.getApplicationContext();
    StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    try {// ww w . j a v a 2 s .c o m
        Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
        Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
        Method getPath = storageVolumeClazz.getMethod("getPath");
        Object result = getVolumeList.invoke(mStorageManager);
        final int length = Array.getLength(result);
        final String[] paths = new String[length];
        for (int i = 0; i < length; i++) {
            Object storageVolumeElement = Array.get(result, i);
            paths[i] = (String) getPath.invoke(storageVolumeElement);
        }
        return paths;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getWindowWidth(Context context) {
    Display display = ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//from  www .  j a  v a  2  s.co m
    return display.getWidth();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getWindowHeight(Context context) {
    Display display = ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//from   w w  w  .  ja va  2  s  .c o m
    return display.getHeight();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();/*from  www  . j a va2 s.c o  m*/
    editor.putBoolean(key, value);
    editor.commit();
}

From source file:Main.java

private static DisplayMetrics getDisplayMetrics(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    dm = context.getApplicationContext().getResources().getDisplayMetrics();
    return dm;//from  w w w .j  a  v a 2 s  . co m
}

From source file:Main.java

public static final boolean isDebuggable(Context context) {
    return isDebuggable((Application) context.getApplicationContext());
}