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) { try {/*from w w w .j av a2s . c o m*/ PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); int version = info.versionCode; return version; } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static String getVersion(Context context) { try {/* w ww . j ava 2 s.c om*/ PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); String version = info.versionName; return version; } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String getVersionName(Context context) throws PackageManager.NameNotFoundException { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); return packageInfo.versionName; }
From source file:Main.java
public static String getAppVersionName(Context context) { String versionName = ""; try {/*from www . j a v a 2 s . c o m*/ PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return ""; } } catch (Exception e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static boolean isUpToDate(String v2, Context context) { try {/*from www .ja va2s. co m*/ PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); String version = info.versionName; return v2.equals(version); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return false; } }
From source file:Main.java
public static String getAppVersion(Context context) { String versionName = null;// w w w . jav a 2s . c o m try { PackageManager pManager = context.getPackageManager(); PackageInfo pInfo = pManager.getPackageInfo(context.getPackageName(), 0); versionName = pInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static Drawable getAppIcon(Context mContext, String packageName) { try {//from w w w. j a va 2 s. c o m PackageManager manager = mContext.getPackageManager(); PackageInfo info = manager.getPackageInfo(packageName, 0); Drawable drawable = info.applicationInfo.loadIcon(manager); return drawable; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getAppVersionCode(Context context) { int versionCode = 0; try {//from ww w . j av a 2 s . c o m PackageManager pManager = context.getPackageManager(); PackageInfo pInfo = pManager.getPackageInfo(context.getPackageName(), 0); versionCode = pInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static String getAppVersionName(Context context) { PackageManager pm = context.getPackageManager(); try {/*from w w w . j a va 2 s . com*/ PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); return pi == null ? "" : pi.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String getAppPackageName(Context context) { String packageName = null;//w w w. jav a 2 s. c om try { PackageManager pManager = context.getPackageManager(); PackageInfo pInfo = pManager.getPackageInfo(context.getPackageName(), 0); packageName = pInfo.packageName; } catch (NameNotFoundException e) { e.printStackTrace(); } return packageName; }