List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); int versionCode = 0; try {/* ww w . j av a2s . co m*/ PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0); versionCode = packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static boolean isInstalledOnSdCard(Context context) { // check for API level 8 and higher if (isCompatible(8)) { PackageManager pm = context.getPackageManager(); try {//from w ww . ja v a 2s . c om PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); ApplicationInfo ai = pi.applicationInfo; return (ai.flags & 0x00040000 /* * ApplicationInfo. * FLAG_EXTERNAL_STORAGE */) == 0x00040000 /* * ApplicationInfo. * FLAG_EXTERNAL_STORAGE */; } catch (NameNotFoundException e) { // ignore } } // check for API level 7 - check files dir try { String filesDir = context.getFilesDir().getAbsolutePath(); if (filesDir.startsWith("/data/")) { return false; } else if (filesDir.contains(Environment.getExternalStorageDirectory().getPath())) { return true; } } catch (Throwable e) { // ignore } return false; }
From source file:Main.java
public static String getVersionName(Context context) { PackageManager pm = context.getPackageManager(); String versionName = ""; try {//w w w .j av a2 s. com PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0); versionName = packageInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static String getAppVersionName(Context context) { PackageManager manager = context.getPackageManager(); PackageInfo info;//from w w w . j a v a 2 s .c o m String versionName = null; try { info = manager.getPackageInfo(context.getPackageName(), 0); versionName = info.versionName; } catch (PackageManager.NameNotFoundException e1) { e1.printStackTrace(); } return versionName; }
From source file:Main.java
public static Intent getDefaultClockIntent(Context context) { PackageManager pm = context.getPackageManager(); for (String packageName : CLOCK_PACKAGES) { try {//from w ww . jav a 2 s. c om pm.getPackageInfo(packageName, 0); return pm.getLaunchIntentForPackage(packageName); } catch (PackageManager.NameNotFoundException ignored) { } } return null; }
From source file:Main.java
public static boolean checkSignature(Context ctx, String packageName, String srcSignature) { PackageManager pm = ctx.getPackageManager(); try {// w w w.ja va 2s .c om PackageInfo pack = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); Signature[] signatures = pack.signatures; String destSignature = getApkSignatureMD5String(signatures[0]); return destSignature.equalsIgnoreCase(srcSignature); } catch (NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = null;//from w w w . j av a2 s. c o m try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo.versionCode; }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = null;/*from ww w . ja va2 s.c om*/ try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo; }
From source file:Main.java
public static void runApp(Context context, String paramString) { PackageManager localPackageManager = context.getPackageManager(); try {// w w w . ja va2s .c om PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramString, 0); Intent localIntent1 = new Intent("android.intent.action.MAIN", null); localIntent1.setPackage(localPackageInfo.packageName); ResolveInfo localResolveInfo = (ResolveInfo) localPackageManager.queryIntentActivities(localIntent1, 0) .iterator().next(); if (localResolveInfo != null) { String str1 = localResolveInfo.activityInfo.packageName; String str2 = localResolveInfo.activityInfo.name; Intent localIntent2 = new Intent("android.intent.action.MAIN"); localIntent2.setComponent(new ComponentName(str1, str2)); context.startActivity(localIntent2); } } catch (PackageManager.NameNotFoundException localNameNotFoundException) { localNameNotFoundException.printStackTrace(); } }
From source file:Main.java
/** * Checks if an App is Installed./*from ww w.j a va 2s . c om*/ * * @return true if installed false otherwise */ public static boolean isAppInstalled(Context context, String packageName) { if (context == null) return false; PackageManager pm = context.getApplicationContext().getPackageManager(); boolean isAppInstalled = false; try { pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); isAppInstalled = true; } catch (PackageManager.NameNotFoundException e) { isAppInstalled = false; } return isAppInstalled; }