List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getAppVersionName(Context context) { PackageManager manager = context.getPackageManager(); PackageInfo info;/*from w w w . j a va2s .c om*/ try { info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); return "1.0"; } }
From source file:Main.java
/** * Get give package version name.//from www . j a va 2 s . c o m * * @param context Object of {@link Context}. * @param pkg Package name. * @return {@link String} of version name. */ public final static String getAppVersionName(Context context, String pkg) { PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(pkg, 0); return info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getVersionName(Context context) { try {//from w ww .j av a 2 s.co m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { return ""; } }
From source file:Main.java
public static String getOldVersionPath(Context context) { try {/* www . jav a2 s .co m*/ ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); return appInfo.sourceDir; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static ResolveInfo getDefaultBrowser(Context context) { PackageManager pm = context.getPackageManager(); Intent query = new Intent(); query.setAction(Intent.ACTION_VIEW); query.setData(Uri.parse("http://localhost")); ResolveInfo info = pm.resolveActivity(query, 0); if (info == null) { return info; }/*from w w w. ja v a2 s. co m*/ // Could be a Chooser if (info.activityInfo.packageName.equals("android")) { return null; } return info; }
From source file:Main.java
public static String getAppVersion(Context context) { String appVersion = "???"; if (context.getPackageManager() != null) { try {//w w w .j a v a 2s.c om appVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } } return appVersion; }
From source file:Main.java
public static String getPackageName(Context context) { try {//from www. j a v a 2 s . c o m PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.packageName; } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getAppVersion(Context context) { try {/*from ww w . jav a 2 s . co m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { // should never happen throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
public static boolean isFirstPublish(Context context) { try {//w ww.ja va2s. c o m ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; return bundle.getBoolean("FIRST_LAUNCHER"); } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static String getVersion(Context context) { try {//from w ww.j a va 2 s.c om PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); return "1.0.0"; } }