List of utility methods to do Context Check
boolean | isAppInstalled(Context context) is App Installed PackageManager manager = context.getPackageManager(); try { manager.getPackageInfo(PACKAGE_NAME, 0); return true; } catch (NameNotFoundException e) { return false; |
boolean | isAppInstalled(Context context, String uri) Check if package installed PackageManager pm = context.getPackageManager(); boolean appInstalled; try { assert pm != null; pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); appInstalled = true; } catch (PackageManager.NameNotFoundException e) { appInstalled = false; ... |
boolean | isAppOnForeground(Context context) is App On Foreground ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); if (appProcesses == null) return false; for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName()) ... |
boolean | isApplicationBroughtToBackground( final Context context) Checks if the application is in the background (i.e behind another application's Activity). if (context .checkCallingOrSelfPermission(Manifest.permission.GET_TASKS) == PackageManager.PERMISSION_DENIED) return false; ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; ... |
boolean | isApplicationBroughtToBackground( final Context context) Checks if the application is in the background (i.e behind another application's Activity). ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals( context.getPackageName())) { return true; ... |
boolean | isCallable(Context context, String url) is Callable String mimeTypeExtension = URLConnection .guessContentTypeFromName(url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), mimeTypeExtension); List<ResolveInfo> list = context.getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; ... |
boolean | isConnected(Context connext) is Connected ConnectivityManager connectivityManager = (ConnectivityManager) connext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if (info != null && info.isConnected()) { return true; return false; |
boolean | isConnected(Context context) is Connected ConnectivityManager conn = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
|
boolean | isDebugCertificateCheck(final Context context) is Debug Certificate Check final X500Principal DEBUG_CERTIFICATE_DN = new X500Principal( "CN=Android Debug,O=Android,C=US"); boolean debuggable = false; try { Signature[] signatures = getSignatures(context); for (int i = 0; i < signatures.length; i++) { X509Certificate certificate = generateX509CertificateFromSignature(signatures[i]); debuggable = certificate.getSubjectX500Principal().equals( ... |
boolean | isDebuggable(final Context context, final boolean includeDefaultDebugCertificateCheck) Check whether the application is debuggable. boolean debuggable = (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)); if (!debuggable && includeDefaultDebugCertificateCheck) { debuggable = isDebugCertificateCheck(context); return debuggable; |