List of utility methods to do Context Check
boolean | isSensAppInstalled(Context context) is Sens App Installed try { context.getPackageManager().getApplicationInfo( "org.sensapp.android.sensappdroid", 0); } catch (PackageManager.NameNotFoundException e) { return false; return true; |
boolean | isServiceRunning(Context ctx, String className) is Service Running boolean isRunning = false; ActivityManager activityManager = (ActivityManager) ctx .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> servicesList = activityManager .getRunningServices(Integer.MAX_VALUE); Iterator<RunningServiceInfo> l = servicesList.iterator(); while (l.hasNext()) { RunningServiceInfo si = (RunningServiceInfo) l.next(); ... |
boolean | isServiceRunning(Context ctx, String className) is Service Running boolean isRunning = false; ActivityManager activityManager = (ActivityManager) ctx .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> servicesList = activityManager .getRunningServices(Integer.MAX_VALUE); Iterator<RunningServiceInfo> l = servicesList.iterator(); while (l.hasNext()) { RunningServiceInfo si = (RunningServiceInfo) l.next(); ... |
boolean | isSystemApplication(Context context, String packageName) is System Application PackageManager manager = context.getPackageManager(); try { PackageInfo packageInfo = manager.getPackageInfo(packageName, PackageManager.GET_CONFIGURATIONS); if (packageInfo != null && (packageInfo.applicationInfo.flags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) != 0) { return true; } catch (Exception e) { e.printStackTrace(); return false; |
boolean | isTablet(Context ctx) is Tablet try { DisplayMetrics dm = ctx.getResources().getDisplayMetrics(); float screenWidth = dm.widthPixels / dm.xdpi; float screenHeight = dm.heightPixels / dm.ydpi; double size = Math.sqrt(Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2)); return size >= 6; } catch (Throwable t) { ... |
boolean | isTablet(final Context context) Used to determine if the device is a tablet or not final int layout = context.getResources().getConfiguration().screenLayout; return (layout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; |
boolean | isThemeInstalled(Context c, String theme) is Theme Installed try { c.getPackageManager().getPackageInfo(theme, PackageManager.GET_ACTIVITIES); return true; } catch (Exception e) { return false; |
boolean | isUpdateAvailable(Context paramContext, String paramString) is Update Available try { HttpURLConnection localHttpURLConnection = (HttpURLConnection) new URL( paramString).openConnection(); long l1 = localHttpURLConnection.getHeaderFieldDate( "Last-Modified", System.currentTimeMillis()); localHttpURLConnection.disconnect(); long l2 = PreferenceManager.getDefaultSharedPreferences( paramContext.getApplicationContext()).getLong( ... |
boolean | isValidSigningKey(final Context context, final String certificateToCheckAgainst) Check whether the signing key can be validated. try { Signature[] signatures = getSignatures(context); for (int i = 0; i < signatures.length; i++) { X509Certificate certificate = generateX509CertificateFromSignature(signatures[i]); String sha1 = getCertificateSHA1(certificate); if (!certificateToCheckAgainst.equalsIgnoreCase(sha1)) { return false; } catch (PackageManager.NameNotFoundException e) { } catch (CertificateException e) { } catch (NoSuchAlgorithmException e) { return true; |
boolean | isVoiceSearchServiceExist(Context context) is Voice Search Service Exist InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> mInputMethodProperties = imm .getEnabledInputMethodList(); boolean isVoiceSearchServiceEnabled = false; for (int i = 0; i < mInputMethodProperties.size(); i++) { InputMethodInfo imi = mInputMethodProperties.get(i); if (DEBUG) ... |