List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getAppVerName(Context ctx) { try {//from www. j ava 2 s . co m PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_CONFIGURATIONS); return info.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static int getAppVersionCode(Context context) { try {/*w w w . j ava2 s. c o m*/ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packInfo = null;/*from w w w. j a v a 2 s. c o m*/ try { packInfo = packageManager.getPackageInfo(context.getPackageName(), 0); return packInfo.versionCode; } catch (Exception e) { } return 0; }
From source file:Main.java
public static boolean isAppInstaled(Context context, String uri) { PackageManager pm = context.getPackageManager(); try {//w w w . ja va 2 s . c o m pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static int getAppVersion(Context context) { try {/* w ww . j a va2 s . c om*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static boolean hasPermission(Context context, String permissionStr) { PackageManager pm = context.getPackageManager(); boolean permission = (PackageManager.PERMISSION_GRANTED == pm.checkPermission(permissionStr, context.getPackageName()));// w w w . java 2 s .c o m return permission; }
From source file:Main.java
public static boolean checkAppExists(Context context, String packageName) { try {//from w w w. ja va 2 s .c o m context.getPackageManager().getApplicationInfo(packageName, 0); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context) { try {// w w w. j a va 2s. c o m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info; } catch (NameNotFoundException e) { } return null; }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from ww w. j av a 2 s . c o m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static boolean isAppInstalled(Context context, String pkg) { PackageManager pm = context.getPackageManager(); boolean installed = false; try {/*from w ww . j a v a 2 s . co m*/ pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES); installed = true; } catch (Exception e) { installed = false; } return installed; }