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 String getVersion(Context context) { try {//from w w w .j a v a2 s. c o m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); return "1.0.0"; } }
From source file:Main.java
/** * check if assign package is installed in system * *///from w w w . j a v a2 s.co m public static boolean isPackageInstalled(String packagename, Context context) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); return true; } catch (NameNotFoundException e) { return false; } }
From source file:Main.java
public static int getAppVersionCode(Context context) { try {/*from www . ja v a 2s .co m*/ 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 PackageInfo getPackageInfo(Context context) { PackageInfo packageInfo = null;/* www . j av a 2 s .co m*/ try { PackageManager pm = context.getPackageManager(); packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS); return packageInfo; } catch (Exception e) { e.printStackTrace(); } return packageInfo; }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from w w w . j a v a 2s . c om 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 int getAppVersionCode(Context context) { int versioncode = -1; try {/*from w ww . j av a 2 s. c o m*/ // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versioncode = pi.versionCode; } catch (Exception e) { Log.e("VersionInfo", "Exception", e); } return versioncode; }
From source file:Main.java
public static int getVersionCode(Context context, String pkgName) { try {//from w w w . ja v a2 s.co m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(pkgName, 0); return info.versionCode; } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static String getVersionName(Context context, String pkgName) { try {// ww w .j a v a2 s. co m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(pkgName, 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getVersion(Context context) { try {/*from w w w .j a v a 2s. c om*/ PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from w w w.j a v a 2s . c om PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); int version = info.versionCode; return version; } catch (Exception e) { return 0; } }