List of usage examples for android.app Application getPackageManager
@Override
public PackageManager getPackageManager()
From source file:Main.java
public static boolean isApkDebuggable(Application application) { PackageManager pm = application.getPackageManager(); try {//from www. ja va 2s .c o m return ((pm.getApplicationInfo(application.getPackageName(), 0).flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0); } catch (NameNotFoundException e) { return false; } }
From source file:Main.java
public static final boolean isInstalledOnSDCard(Application app) { try {/* ww w.j av a2s . c o m*/ String packageName = app.getPackageName(); PackageInfo info = app.getPackageManager().getPackageInfo(packageName, 0); String dir = info.applicationInfo.sourceDir; for (String path : INTERNAL_PATH) { if (path.equals(dir.substring(0, path.length()))) return false; } } catch (PackageManager.NameNotFoundException exp) { throw new IllegalArgumentException(exp); } return true; }
From source file:Main.java
public static String getHomeLauncherName(Application application) { final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); final ResolveInfo res = application.getPackageManager().resolveActivity(intent, 0); if (res.activityInfo == null) { return ""; }/*from www . jav a 2s.c o m*/ return res.activityInfo.loadLabel(application.getPackageManager()).toString(); }
From source file:Main.java
public static boolean isLauncherDefault(Application application) { final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); final ResolveInfo res = application.getPackageManager().resolveActivity(intent, 0); if (res.activityInfo == null) { return false; } else if ("android".equals(res.activityInfo.packageName)) { return false; } else {// w ww. ja va 2s .com if (res.activityInfo.packageName.equals(application.getPackageName())) return true; else return false; } }
From source file:com.jeffthefate.stacktrace.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/*from w ww . j ava 2 s . c o m*/ */ public static boolean register(Application app) { mCallback = (OnStacktraceListener) app; Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = app.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(app.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = app.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) stackTracesFound = true; new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { // Register default exceptions handler Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:net.wequick.small.Small.java
public static void preSetUp(Application context) { sContext = context;// w ww .j av a 2 s . co m // Register default bundle launchers registerLauncher(new ActivityLauncher()); registerLauncher(new ApkBundleLauncher()); registerLauncher(new WebBundleLauncher()); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); // Check if host app is first-installed or upgraded int backupHostVersion = getHostVersionCode(); int currHostVersion = 0; try { PackageInfo pi = pm.getPackageInfo(packageName, 0); currHostVersion = pi.versionCode; } catch (PackageManager.NameNotFoundException ignored) { // Never reach } if (backupHostVersion != currHostVersion) { sIsNewHostApp = true; setHostVersionCode(currHostVersion); } else { sIsNewHostApp = false; } // Collect host certificates try { Signature[] ss = pm.getPackageInfo(Small.getContext().getPackageName(), PackageManager.GET_SIGNATURES).signatures; if (ss != null) { int N = ss.length; sHostCertificates = new byte[N][]; for (int i = 0; i < N; i++) { sHostCertificates[i] = ss[i].toByteArray(); } } } catch (PackageManager.NameNotFoundException ignored) { } // Check if application is started after unexpected exit (killed in background etc.) ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName launchingComponent = am.getRunningTasks(1).get(0).topActivity; ComponentName launcherComponent = pm.getLaunchIntentForPackage(packageName).getComponent(); if (!launchingComponent.equals(launcherComponent)) { // In this case, system launching the last restored activity instead of our launcher // activity. Call `setUp' synchronously to ensure `Small' available. setUp(context, null); } }