List of usage examples for android.content Context getApplicationInfo
public abstract ApplicationInfo getApplicationInfo();
From source file:com.hanuor.sapphire.hub.Internals.java
private static String getAppName(Context context) { int stringId = context.getApplicationInfo().labelRes; if (context.getString(stringId) != null) { return context.getString(stringId); } else {/*from w w w .j a va 2s .c o m*/ return "null_app_name"; } }
From source file:com.github.czy1121.update.app.utils.UpdateUtil.java
public static boolean isDebuggable(Context context) { try {/* w w w .jav a2s. com*/ return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; } catch (Exception e) { } return false; }
From source file:Main.java
/** return the res id of android ( current only the calling package )*/ public static int getResId(String str, Context context) { String packageName;//from w w w. j a va2s. com if (str.startsWith("android.R.")) { packageName = "android"; //android.R.anim.xxx -> R.anim.xxx str = str.substring(str.indexOf(".") + 1); } else { packageName = context.getApplicationInfo().packageName; } //final String packageName = context.getApplicationInfo().packageName; final String[] strs = str.split("\\."); try { //R.drawable.xxx_xx return Class.forName(packageName + ".R$" + strs[1]).getField(strs[2]).getInt(null); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.github.javiersantos.piracychecker.LibraryUtils.java
static boolean isDebug(Context context) { return ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); }
From source file:com.example.shinelon.ocrcamera.MainActivity.java
/** * Gets the folder in which the shared libraries are stored * * @param context The context object.// w w w .j ava2 s . c om * @return The folder in which the shared libraries are stored. */ public static String getSharedLibsPath(Context context) { return context.getApplicationInfo().nativeLibraryDir; }
From source file:uk.ac.horizon.ug.exploding.client.logging.LoggingUtils.java
/** init */ public static synchronized void init(Context context) { String packageName = context.getApplicationInfo().packageName; if (applicationDirName != null) { if (applicationDirName.equals(packageName)) // no-op return; // close and re-initialise? Log.w(TAG, "Re-initialise logging with different package name: " + packageName + " vs " + applicationDirName);//from www . j a v a 2s . c om // TODO Log return; } applicationDirName = packageName; String fileName = "log_" + System.currentTimeMillis() + ".json"; File dir = new File(LOG_ROOT_DIR, applicationDirName); if (dir.mkdir()) Log.i(TAG, "Created log directory " + dir); if (!dir.exists()) { Log.e(TAG, "Log directory does not exist: " + dir + " - cannot log"); return; } if (!dir.isDirectory()) { Log.e(TAG, "Log directory is not a directory: " + dir + " - cannot log"); return; } File file = new File(LOG_ROOT_DIR + applicationDirName, fileName); if (file.exists()) Log.w(TAG, "Appending to existing log: " + file); try { logWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file, true), Charset.forName("UTF-8"))); Log.i(TAG, "Logging to " + file); logFile = file; } catch (Exception e) { Log.e(TAG, "Opening log file " + file + " - cannot log", e); logWriter = null; } logHeader(context); // dump exceptions! final UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // TODO Auto-generated method stub try { JSONStringer js = new JSONStringer(); js.object(); js.key("thread"); js.value(thread.getName()); js.key("exception"); js.value(ex.toString()); js.key("stackTrace"); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); js.value(sw.getBuffer().toString()); js.endObject(); log(LOGTYPE_UNCAUGHT_EXCEPTION, js.toString()); } catch (Exception e) { Log.e(TAG, "Logging uncaught exception", e); } // cascade if (handler != null) handler.uncaughtException(thread, ex); } }); }
From source file:Main.java
/** * Determines whether notifications are enabled for the app represented by |context|. * Notifications may be disabled because either the user, or a management tool, has explicitly * disallowed the Chrome App to display notifications. * * This check requires Android KitKat or later. Earlier versions will return an INDETERMINABLE * status. When an exception occurs, an EXCEPTION status will be returned instead. * * @param context The context to check of whether it can show notifications. * @return One of the APP_NOTIFICATION_STATUS_* constants defined in this class. *//*from www . j a v a 2s . c o m*/ @TargetApi(Build.VERSION_CODES.KITKAT) static int determineAppNotificationStatus(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return APP_NOTIFICATIONS_STATUS_UNDETERMINABLE; } final String packageName = context.getPackageName(); final int uid = context.getApplicationInfo().uid; final AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class appOpsManagerClass = Class.forName(AppOpsManager.class.getName()); @SuppressWarnings("unchecked") final Method checkOpNoThrowMethod = appOpsManagerClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); final Field opPostNotificationField = appOpsManagerClass.getDeclaredField(OP_POST_NOTIFICATION); int value = (int) opPostNotificationField.get(Integer.class); int status = (int) checkOpNoThrowMethod.invoke(appOpsManager, value, uid, packageName); return status == AppOpsManager.MODE_ALLOWED ? APP_NOTIFICATIONS_STATUS_ENABLED : APP_NOTIFICATIONS_STATUS_DISABLED; } catch (RuntimeException e) { } catch (Exception e) { // Silently fail here, since this is just collecting statistics. The histogram includes // a count for thrown exceptions, if that proves to be significant we can revisit. } return APP_NOTIFICATIONS_STATUS_EXCEPTION; }
From source file:com.amitshekhar.utils.PrefHelper.java
public static List<String> getSharedPreferenceTags(Context context) { ArrayList<String> tags = new ArrayList<>(); 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())); }/*from ww w . ja v a 2 s. com*/ } } Collections.sort(tags); return tags; }
From source file:com.teegarcs.mocker.internals.MockerInternals.java
public static boolean isAppOnForeground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); return taskInfo.get(0).topActivity.getPackageName().equals(context.getApplicationInfo().packageName); }
From source file:com.bt.download.android.util.SystemUtils.java
public static int calculateMemoryCacheSize(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); boolean largeHeap = (context.getApplicationInfo().flags & FLAG_LARGE_HEAP) != 0; int memoryClass = am.getMemoryClass(); if (largeHeap) { memoryClass = am.getLargeMemoryClass(); }//from ww w . j ava 2 s .co m // Target ~15% of the available heap. return 1024 * 1024 * memoryClass / 7; }