List of usage examples for android.content Context getApplicationInfo
public abstract ApplicationInfo getApplicationInfo();
From source file:Main.java
/** * Gets the amount of memory available to the application. * * Queries whether the largeHeap manifest flag is set. * * @param context/*from w w w . j av a2s.c o m*/ * the application context * @return the amount of memory in bytes available to the application */ private static int getAvailableMemory(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); boolean largeHeap = (context.getApplicationInfo().flags & 1048576) != 0; int memoryClass = largeHeap ? activityManager.getLargeMemoryClass() : activityManager.getMemoryClass(); return memoryClass * 1048576; }
From source file:Main.java
/** * Check whether the application is debuggable. * The first check is to see what the PackageManager reports. * If wanted, an additional check can be performed by looking at the certificate. * The default auto-generated certificate has the DN 'CN=Android Debug,O=Android,C=US', * as described at http://developer.android.com/tools/publishing/app-signing.html#debugmode * If the app's DN matches this default, it is probably using the debug certificate. * * @param context Context// ww w.ja v a 2 s . co m * @return true when the app is debuggable, otherwise false */ public static boolean isDebuggable(final Context context, final boolean includeDefaultDebugCertificateCheck) { boolean debuggable = (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)); if (!debuggable && includeDefaultDebugCertificateCheck) { debuggable = isDebugCertificateCheck(context); } return debuggable; }
From source file:com.commonsware.android.backup.BackupService.java
static File getSharedPrefsDir(Context ctxt) { return (new File(new File(ctxt.getApplicationInfo().dataDir), "shared_prefs")); }
From source file:Main.java
/** * Get the name of this app as specified in manifest. * * @param context/* w w w . ja v a 2 s .c om*/ * @return String */ public static String getAppName(Context context) { try { PackageManager packageManager = context.getPackageManager(); return packageManager.getApplicationLabel(context.getApplicationInfo()).toString(); } catch (Exception e) { e.printStackTrace(); } return "Unknown"; }
From source file:Main.java
public static boolean areNotificationsEnabled(Context context) { AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); ApplicationInfo appInfo = context.getApplicationInfo(); String pkg = context.getApplicationContext().getPackageName(); int uid = appInfo.uid; try {//www. ja v a 2 s . c om Class<?> appOpsClass = Class.forName(AppOpsManager.class.getName()); Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); int value = (Integer) opPostNotificationValue.get(Integer.class); return ((Integer) checkOpNoThrowMethod.invoke(appOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED); } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | InvocationTargetException | IllegalAccessException | RuntimeException e) { return true; } }
From source file:com.facebook.stetho.inspector.domstorage.SharedPreferencesHelper.java
public static List<String> getSharedPreferenceTags(Context context) { ArrayList<String> tags = new ArrayList<String>(); String rootPath = context.getApplicationInfo().dataDir + "/shared_prefs"; File root = new File(rootPath); if (root.exists()) { for (File file : root.listFiles()) { String fileName = file.getName(); if (fileName.endsWith(PREFS_SUFFIX)) { tags.add(fileName.substring(0, fileName.length() - PREFS_SUFFIX.length())); }// w ww .j a v a2s . co m } } return tags; }
From source file:Main.java
private static String getChannelFromApk(Context context, String channelKey) { ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; String key = "META-INF/" + channelKey; String ret = ""; ZipFile zipfile = null;//from ww w .j av a2s . c om try { zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) { ret = entryName; break; } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } String[] split = ret.split("_"); String channel = ""; if (split != null && split.length >= 2) { channel = ret.substring(split[0].length() + 1); } return channel; }
From source file:com.google.android.gms.common.internal.C1339l.java
public static String m4741a(Context context) { String str = context.getApplicationInfo().name; if (TextUtils.isEmpty(str)) { str = context.getPackageName();//from w w w . java 2s. c o m try { str = ar.m5144b(context).m5143b(context.getPackageName()).toString(); } catch (NameNotFoundException e) { } } return str; }
From source file:Main.java
public static String getMetaData(Context app, String name) { Bundle bundle = app.getApplicationInfo().metaData; if (bundle != null) { return bundle.getString(name); } else {/*from ww w . j ava2 s .c om*/ XmlResourceParser parser = null; AssetManager assmgr = null; try { assmgr = (AssetManager) AssetManager.class.newInstance(); Method e = AssetManager.class.getDeclaredMethod("addAssetPath", new Class[] { String.class }); e.setAccessible(true); int cookie = ((Integer) e.invoke(assmgr, new Object[] { app.getApplicationInfo().sourceDir })) .intValue(); if (cookie != 0) { String ANDROID_RESOURCES = "http://schemas.android.com/apk/res/android"; parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml"); boolean findAppMetadata = false; int event = parser.getEventType(); while (event != 1) { switch (event) { case 2: String nodeName = parser.getName(); String metadataName; if ("meta-data".equals(nodeName)) { findAppMetadata = true; metadataName = parser.getAttributeValue(ANDROID_RESOURCES, "name"); if (metadataName.equals(name)) { String var12 = parser.getAttributeValue(ANDROID_RESOURCES, "value"); return var12; } } else if (findAppMetadata) { metadataName = null; return metadataName; } default: event = parser.next(); } } } } catch (Throwable var16) { var16.printStackTrace(); } finally { if (parser != null) { parser.close(); } if (assmgr != null) { assmgr.close(); } } return null; } }
From source file:Main.java
/** * Determines if this application is top activity * @param context Context to be examined * @return true if this application is a top activity; false otherwise *//*from ww w. j av a2s. co m*/ public static boolean isTopApplication(Context context) { ComponentName activity = getTopActivity(context); if (activity == null) { return false; } return activity.getPackageName().equals(context.getApplicationInfo().packageName); }