List of utility methods to do Context Check
boolean | isExisting(Context context, Uri uri, String selection, String[] args) Determine whether or not a give URI has an item matching the specified selected and arguments. Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, null, selection, args, null); return cursor.getCount() > 0; } finally { if (cursor != null) cursor.close(); ... |
boolean | isFileExist(Context ctx, String filename) is File Exist File rootDir = ctx.getFilesDir(); if (rootDir.exists()) { File file = new File(rootDir, filename); return file.exists(); return false; |
boolean | isFree(Context context) is Free return context.getApplicationContext().getPackageName() .equals("com.pedroedrasousa.wobblybubbleslite"); |
boolean | isGPRSAvailable(Context context) public static boolean isGPRSAvailable(Context context) this will check whether GPRS is available or not ConnectivityManager connect = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfoMobile = connect .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (netInfoMobile.isConnected()) return true; else return false; ... |
boolean | isGoogleAccountPresent(Context ctx) is Google Account Present AccountManager am = AccountManager.get(ctx); Account[] accounts = am.getAccountsByType("com.google"); if (accounts == null || accounts.length == 0) { return false; } else { return true; |
boolean | isGpsEnabled(Context context) is Gps Enabled LocationManager lm = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
boolean | isHeadsetPluggedIn(Context context) is Headset Plugged In Intent headsetIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); if (headsetIntent != null) { Bundle extraData = headsetIntent.getExtras(); return !(extraData.getInt(EXTRA_HEADSET_STATE_KEY) == 0); return false; |
boolean | isInstalledThroughPlayStore(final Context context) Check whether the application is installed through the Play Store. final PackageManager packageManager = context.getPackageManager(); final String packageInstallerName = packageManager .getInstallerPackageName(getPackageName(context)); if ("com.android.vending".equals(packageInstallerName)) { return true; return false; |
boolean | isLandscape(Context context) is Landscape Display display = ((WindowManager) context .getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); if (display.getWidth() > display.getHeight()) { return true; } else { return false; |
boolean | isLandscape(final Context context) Used to determine if the device is currently in landscape mode final int orientation = context.getResources().getConfiguration().orientation; return orientation == Configuration.ORIENTATION_LANDSCAPE; |