List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
@Deprecated public static int getApkVersion(Context context) { int i = 0;/*w w w . j a v a 2 s .c om*/ try { return context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode; } catch (NameNotFoundException e) { Log.w("GooglePlayServicesUtil", "Google Play services is missing."); return i; } }
From source file:Main.java
/** * get version code of this app//w w w . j a v a 2 s . c o m * @param context context * @return version code */ public static int getVersionCode(Context context) { if (pm == null) { pm = context.getPackageManager(); } try { return pm.getPackageInfo(context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
/** * get version name of this app/*from w w w.j ava 2s. co m*/ * @param context context * @return version name */ public static String getVersionName(Context context) { if (pm == null) { pm = context.getPackageManager(); } try { return pm.getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * @return Application's version code from the {@code PackageManager}. */// w w w.j a v a2 s . c o m public static int getAppVersion(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { // should never happen throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
/** * Check if BerryMotes app is installed * /*from w w w . j a v a2 s. c o m*/ * @param context Android context * @return true if BerryMotes is installed */ public static boolean isBerryMotesInstalled(Context context) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(BERRYMOTES_NAME, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static int getVersionCode(Context context) { try {/*from w w w . j a va2 s.com*/ PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static boolean isInstalled(Context context, String packageName) { PackageManager manager = context.getPackageManager(); try {// w w w .j a va 2 s .c o m manager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); return true; } catch (NameNotFoundException e) { return false; } }
From source file:Main.java
public static void launchApp(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); Intent intent = packageManager.getLaunchIntentForPackage(packageName); if (intent != null) { context.startActivity(intent);/*from w w w . j ava 2s . com*/ } }
From source file:Main.java
public static int getVersionCode(Context context) { try {//w ww.j a v a2 s . c om final PackageInfo packInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = null;// ww w .j a va2s . com try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return packageInfo.versionCode; }