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
private static PackageInfo getPackageInfo(Context context, String pkgName) { PackageInfo packageInfo = null;//from w w w .j ava 2s .c om try { PackageManager pm = context.getPackageManager(); packageInfo = pm.getPackageInfo(pkgName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); packageInfo = new PackageInfo(); packageInfo.versionCode = 1; packageInfo.versionName = "1.0"; } return packageInfo; }
From source file:Main.java
public static String getAppVersionName(Context context) { String versionName = ""; try {//from www . ja v a 2s . c o m // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return null; } } catch (Exception e) { Log.e("VersionInfo", "Exception", e); } return versionName; }
From source file:Main.java
public static boolean isPackageInstalled(final String packageName, final PackageManager pm) { String mVersion;//from w w w . ja v a 2 s . c o m try { mVersion = pm.getPackageInfo(packageName, 0).versionName; if (mVersion.equals(null)) { return false; } } catch (NameNotFoundException e) { return false; } return true; }
From source file:Main.java
public static boolean isPackageInstalled(String packageName, PackageManager pm) { try {//from w w w. j av a2 s . c o m String mVersion = pm.getPackageInfo(packageName, 0).versionName; if (mVersion == null) { return false; } } catch (PackageManager.NameNotFoundException notFound) { Log.e(TAG, "Package could not be found!", notFound); return false; } return true; }
From source file:Main.java
public static boolean isPackageInstalled(Context context, String packagename) { PackageManager pm = context.getPackageManager(); try {/*from www. j a va 2 s. co m*/ PackageInfo info = pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); return info != null; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static boolean hasInstalledWx(Activity activity) { try {//from w w w . java2 s .com PackageManager manager = activity.getPackageManager(); PackageInfo info = manager.getPackageInfo(WX_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); if (info != null) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static String getAppVersionName(Context context) { String versionName = ""; try {//from w w w.j a v a2 s . com // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return ""; } } catch (Exception e) { Log.e("VersionInfo", "Exception", e); } return versionName; }
From source file:Main.java
public static String getAppVersion(Context context) { PackageManager pm = context.getPackageManager(); try {//from w w w. j a va 2s . c om PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static int getAppCode(Context context) { int versionCode = 0; try {//from w ww . ja v a 2 s .c o m // ---get the package info--- PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionCode = pi.versionCode; if (versionCode <= 0) { return 0; } } catch (Exception e) { Log.e("VersionInfo", "Exception", e); } return versionCode; }
From source file:Main.java
public static boolean isSystem(String packageName, Context context) { try {// w ww. ja v a 2s .c o m PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageInfo(packageName, 0); return ((info.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0); /* PackageInfo pkg = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES); return (pkg != null && pkg.signatures != null && pkg.signatures.length > 0 && sys.signatures.length > 0 && sys.signatures[0].equals(pkg.signatures[0])); */ } catch (PackageManager.NameNotFoundException ignore) { return false; } }