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

booleanisLocationEnabledGPS(Context c)
is Location Enabled GPS
LocationManager lm = (LocationManager) c
        .getSystemService(Context.LOCATION_SERVICE);
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
booleanisMobile(Context context)
is Mobile
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager
        .getActiveNetworkInfo();
if (activeNetInfo != null
        && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
    return true;
return false;
booleanisMobilityInstalled(Context context)
Returns true if mobility and accelservice are installed
return getMobilityPackageInfo(context) != null;
BooleanisNetAvailable(Context context)
is Net Available
try {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiInfo = connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobileInfo = connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
...
booleanisOnline(Context c)
is Online
try {
    ConnectivityManager cm = (ConnectivityManager) c
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo().isConnectedOrConnecting();
} catch (Exception e) {
    return false;
booleanisOnline(Context context)
is Online
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
    return true;
return false;
booleanisOnline(Context context)
is Online
ConnectivityManager con_manager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
return con_manager.getActiveNetworkInfo() != null
        && con_manager.getActiveNetworkInfo().isAvailable()
        && con_manager.getActiveNetworkInfo().isConnected();
booleanisOnline(Context context)
Check if internet connection is up
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
booleanisOnline(Context context)
is Online
ConnectivityManager connMgr = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isConnected());
booleanisPermissionGranted(Context ctx)
Check BATTERY_STATS permission.
PackageManager pm = ctx.getPackageManager();
int perm = pm.checkPermission(
        android.Manifest.permission.BATTERY_STATS,
        ctx.getPackageName());
return (perm == PackageManager.PERMISSION_GRANTED);