List of utility methods to do Context Check
boolean | hasAsymmericMasterSecret(Context context) has Asymmeric Master Secret SharedPreferences settings = context.getSharedPreferences(
PREFERENCES_NAME, 0);
return settings.contains(ASYMMETRIC_LOCAL_PUBLIC);
|
boolean | hasConnection(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 ... |
boolean | hasInternetConnection(Context context) has Internet Connection ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnectedOrConnecting();
|
boolean | hasInternetConnectivity(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; |
boolean | hasNotificationPermission(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; |
boolean | hasOtherSPAppsInstalled(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) { ... |
boolean | hasTelephony(@Nonnull Context context) Checks if the device has the PackageManager#FEATURE_TELEPHONY . PackageManager manager = context.getPackageManager();
return manager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
boolean | hasVibrationPermission(Context context) has Vibration Permission int result = context .checkCallingOrSelfPermission(permission.VIBRATE); return (result == PackageManager.PERMISSION_GRANTED); |
boolean | is3G(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; |
boolean | isAccessibilityEnabled(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; |