Android Utililty Methods Context Check

List of utility methods to do Context Check

Description

The list of methods to do Context Check are organized into topic(s).

Method

booleanisExisting(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();
...
booleanisFileExist(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;
booleanisFree(Context context)
is Free
return context.getApplicationContext().getPackageName()
        .equals("com.pedroedrasousa.wobblybubbleslite");
booleanisGPRSAvailable(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;
...
booleanisGoogleAccountPresent(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;
booleanisGpsEnabled(Context context)
is Gps Enabled
LocationManager lm = (LocationManager) context
        .getSystemService(Context.LOCATION_SERVICE);
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
booleanisHeadsetPluggedIn(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;
booleanisInstalledThroughPlayStore(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;
booleanisLandscape(Context context)
is Landscape
Display display = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE))
        .getDefaultDisplay();
if (display.getWidth() > display.getHeight()) {
    return true;
} else {
    return false;
booleanisLandscape(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;