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

booleanhasAsymmericMasterSecret(Context context)
has Asymmeric Master Secret
SharedPreferences settings = context.getSharedPreferences(
        PREFERENCES_NAME, 0);
return settings.contains(ASYMMETRIC_LOCAL_PUBLIC);
booleanhasConnection(Context c)
has Connection
ConnectivityManager cm = (ConnectivityManager) c
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetwork = cm
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiNetwork != null && wifiNetwork.isConnected()) {
    return true;
NetworkInfo mobileNetwork = cm
...
booleanhasInternetConnection(Context context)
has Internet Connection
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnectedOrConnecting();
booleanhasInternetConnectivity(Context applicationContext)
Checks if there is an usable Internet connection
ConnectivityManager connManager = (ConnectivityManager) applicationContext
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connManager.getActiveNetworkInfo();
if (info != null)
    return info.isConnected();
else
    return false;
booleanhasNotificationPermission(Context context)
has Notification Permission
PackageManager manager = context.getPackageManager();
try {
    return (manager.checkPermission(NOTIFICATION_PERMISSION,
            context.getPackageName()) == PackageManager.PERMISSION_GRANTED);
} catch (Exception e) {
    return false;
booleanhasOtherSPAppsInstalled(Context context)
has Other SP Apps Installed
PackageManager pm = context.getPackageManager();
if (pm == null) {
    Log.e(TAG, "Unable to get package manager reference");
    return false;
List<PackageInfo> packages = pm.getInstalledPackages(0);
final String thisPackage = context.getPackageName();
for (PackageInfo otherPackageInfo : packages) {
...
booleanhasTelephony(@Nonnull Context context)
Checks if the device has the PackageManager#FEATURE_TELEPHONY .
PackageManager manager = context.getPackageManager();
return manager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
booleanhasVibrationPermission(Context context)
has Vibration Permission
int result = context
        .checkCallingOrSelfPermission(permission.VIBRATE);
return (result == PackageManager.PERMISSION_GRANTED);
booleanis3G(Context context)
is G
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager
        .getActiveNetworkInfo();
if (activeNetInfo != null
        && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
    return true;
return false;
booleanisAccessibilityEnabled(Context context, String id)
is Accessibility Enabled
AccessibilityManager am = (AccessibilityManager) context
        .getSystemService(Context.ACCESSIBILITY_SERVICE);
List<AccessibilityServiceInfo> runningServices = am
        .getEnabledAccessibilityServiceList(AccessibilityEvent.TYPES_ALL_MASK);
for (AccessibilityServiceInfo service : runningServices) {
    if (id.equals(service.getId())) {
        return true;
return false;