List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static boolean isInstalled(Context ctx, String pkgName) { try {//from w w w. ja v a 2s . c o m ctx.getPackageManager().getApplicationInfo(pkgName, GET_META_DATA); return true; } catch (NameNotFoundException e) { return false; } }
From source file:Main.java
public static int getUninatllApkInfo(Context context, String archiveFilePath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES); if (info != null) { return info.versionCode; }//from w w w. j a va 2 s . co m return -1; }
From source file:Main.java
public static void openAPK(Context context, String pkgName) { PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(); intent = packageManager.getLaunchIntentForPackage(pkgName); context.startActivity(intent);/*from w w w. ja v a 2 s. c o m*/ }
From source file:Main.java
public static int getVersionCode(Context context) { try {/*from ww w .ja va2 s .c o m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from w ww. ja v a 2 s. c o m PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionCode; } catch (NameNotFoundException nnfe) { Log.e(TAG, "Error finding version code: " + nnfe); } return -1; }
From source file:Main.java
/** * Get give package version code.//from w w w . j a va 2s. c o m * * @param context Object of {@link Context}. * @param pkg package name. * @return Package version code. */ public final static int getAppVersionCode(Context context, String pkg) { PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(pkg, 0); return info.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static boolean isPackageInstalled(Context context, String packageName) { final PackageManager pm = context.getPackageManager(); try {//from ww w .j a v a 2s.com pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static String getVersion(Context context) { try {//ww w . j ava2 s .co m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); return "0"; } }
From source file:Main.java
public static String getVersion(Context context) { try {// ww w . j a va 2 s . c o m 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
/** * Returns <code>true</code> if Locus Pro is installed. * /*from w ww . ja v a2 s. co m*/ * @param context * actual {@link Context} * @return true or false */ public static boolean isLocusProInstalled(Context context) { try { context.getPackageManager().getPackageInfo(LOCUS_PRO_PACKAGE_NAME, 0); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }