List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getVersionName(Context ctx, String pakageName) { try {/*from w w w. ja v a 2 s . co m*/ PackageInfo pInfo = ctx.getPackageManager().getPackageInfo(pakageName, 0); return pInfo.versionName; } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
/** * Gets the application version.//from w ww. j a v a2s .com * * @param context application context * @return application version */ @Nullable public static String getAppVersion(final Context context) { try { return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (final PackageManager.NameNotFoundException e) { return null; } }
From source file:Main.java
public static int getVersionCode(Context ctx, String pakageName) { try {//from w ww. j av a 2 s . com PackageInfo pInfo = ctx.getPackageManager().getPackageInfo(pakageName, 0); return pInfo.versionCode; } catch (Exception e) { e.printStackTrace(); return -1; } }
From source file:Main.java
public static boolean isAppExists(Context context, String packageName) { PackageManager pm = context.getPackageManager(); try {//w ww . j a v a 2 s. c om PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); if (packageInfo != null) { return true; } } catch (NameNotFoundException e) { return false; } return true; }
From source file:Main.java
public static ActivityInfo tryGetActivity(Context context, ComponentName componentName) { try {//from ww w.j a v a 2s .c om return context.getPackageManager().getActivityInfo(componentName, 0); } catch (PackageManager.NameNotFoundException e) { return null; } }
From source file:Main.java
public static int getAppVersionCode(Context context) { int result = -1; PackageManager pm = context.getPackageManager(); PackageInfo info = null;/*from ww w . ja va 2s. c o m*/ try { info = pm.getPackageInfo(context.getPackageName(), 0); result = info.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static String getAppBuild(Context context) { try {/*from w w w. ja v a 2 s . co m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); return String.valueOf(packageInfo.versionCode); } catch (NameNotFoundException e) { return null; } }
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager p = context.getPackageManager(); // GetPackageName () is your current class package name, 0 stands for is // to get version information PackageInfo packInfo;//from w ww . ja v a 2 s. co m try { packInfo = p.getPackageInfo(context.getPackageName(), 0); return packInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static String getDexThumb(Context context) throws NameNotFoundException { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); int code = packageInfo.versionCode; long updateTime = packageInfo.lastUpdateTime; return String.valueOf(updateTime) + "-" + String.valueOf(code); }