List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getPackageByApkFilePath(Context context, String path) { PackageManager pm = context.getPackageManager(); String packageName = ""; PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES); ApplicationInfo appInfo = null;/*from ww w. j a va2s .c o m*/ if (info != null) { appInfo = info.applicationInfo; packageName = appInfo.packageName; // System.out.println("packageName:" + packageName); } return packageName; }
From source file:Main.java
public static int getVersionCode(Context cxt) { try {//www . j a v a 2 s .co m PackageManager manager = cxt.getPackageManager(); PackageInfo info = manager.getPackageInfo(cxt.getPackageName(), 0); return info.versionCode; } catch (Exception e) { e.printStackTrace(); return -1; } }
From source file:Main.java
public static boolean doSignaturesMatch(Context ctx, String pkg1, String pkg2) { boolean match = ctx.getPackageManager().checkSignatures(pkg1, pkg2) == SIGNATURE_MATCH; return match; }
From source file:Main.java
public static int getAppVersionCode(Context context) { try {//from w ww. ja va 2 s . com PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); return pi == null ? -1 : pi.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return -1; } }
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); int versionCode = 0; try {/* www. j a va 2 s. 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 String getVersionName(Context cxt) { try {//from w w w .ja v a 2s . c om PackageManager manager = cxt.getPackageManager(); PackageInfo info = manager.getPackageInfo(cxt.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String getVersionName(Context context) { PackageManager pm = context.getPackageManager(); String versionName = ""; try {// w w w .j a v a 2 s . c o m PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0); versionName = packageInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static boolean isUpdatedVersion(Context context) { final PackageManager packageManager = context.getPackageManager(); Intent intent = packageManager.getLaunchIntentForPackage("pay.with.slydepay"); if (intent == null) { return false; }//from w ww .j a v a 2s.com List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:Main.java
/** Checks if a package is installed. * //www. j a v a 2 s .c o m * @param context Context to be used to verify the existence of the package. * @param packageName Package name to be searched. * @return true if the package is discovered; false otherwise */ public static boolean isPackageInstalled(Context context, String packageName) { try { context.getPackageManager().getApplicationInfo(packageName, 0); return true; } catch (Exception e) { return false; } }
From source file:Main.java
@SuppressWarnings("unused") public static void launchApk(Context context, String launchApkUrl) { PackageManager pm = context.getPackageManager(); Intent intent = pm.getLaunchIntentForPackage(launchApkUrl); context.startActivity(intent);//from w w w. ja v a2s. co m }