List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:Main.java
public static boolean isWifiActive(Context icontext) { Context context = icontext.getApplicationContext(); ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] info;/* w ww. j a va 2s.c om*/ if (connectivity != null) { info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) { return true; } } } } return false; }
From source file:Main.java
public static int getTrainingWordsSetting(Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); String count = preferences.getString(TRAINING_WORDS_COUNT, Integer.toString(TRAINING_VIEW_PAGER_COUNT)); try {//from w w w . jav a2s .c o m return Integer.parseInt(count); } catch (NumberFormatException ex) { return TRAINING_VIEW_PAGER_COUNT; } }
From source file:Main.java
public static SharedPreferences getPrefs(Context ctx, String prefsKey) { return ctx.getApplicationContext().getSharedPreferences(prefsKey, Context.MODE_PRIVATE); }
From source file:Main.java
/** * Method for mapping the name of an image with its res folder filename. * //from www .ja va2 s. com * @param context The context from the requested class to map the requested resource. * @param image String name of the image file * @return int Id of the the requested image file from the res folder. * */ public static int getImageId(Context context, String image) { int id = context.getApplicationContext().getResources().getIdentifier(image, "drawable", context.getPackageName()); return id; }
From source file:Main.java
/** * Checking device has camera hardware or not *//* w ww. ja va 2s. c o m*/ public static boolean isDeviceSupportCamera(Context context) { // this device has a camera return context.getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); }
From source file:Main.java
public static void showToastShort(Context context, String message) { Toast toast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();/* w ww . ja v a 2 s . c o m*/ }
From source file:Main.java
public static String getDataDirectory(Context context) { String dirname = String.format("/data/data/%s/", context.getApplicationContext().getPackageName()); return dirname; }
From source file:Main.java
public static String getIMEI(Context context) { TelephonyManager manager = (TelephonyManager) context.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); return manager.getSimSerialNumber(); }
From source file:Main.java
public static String getIMSI(Context context) { TelephonyManager manager = (TelephonyManager) context.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); return manager.getSubscriberId(); }
From source file:Main.java
public static int getInt(Context context, String key, int defValue) { SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE); return sp.getInt(key, defValue); }