List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static String getAppVersionName(Context context) { try {//w ww. j a va 2 s. com PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); return info.versionName; } catch (NameNotFoundException e) { return ""; } }
From source file:Main.java
/** * Returns version number./*from w ww . ja va2 s. c om*/ * * @param context Context * @return Version code */ public static int getVersionCode(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { return 0; } }
From source file:Main.java
/** * Returns version name./*from w ww .j av a 2s. c o m*/ * * @param context Context * @return Version name */ public static String getVersionName(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (NameNotFoundException e) { return ""; } }
From source file:Main.java
/** * Extract the app full file system location. * @param context of the application that will be use as base point. * @return Full application file system url. * @throws PackageManager.NameNotFoundException *///from w w w.ja v a 2s .com private static String getSourcePath(Context context) throws PackageManager.NameNotFoundException { return context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).sourceDir; }
From source file:Main.java
/** * Gets the application version./*from w w w. j a v a 2 s. 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 String getVersion(Context ctx) { PackageInfo pInfo;/* w w w .j ava 2 s.co m*/ try { pInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0); return pInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String getAppBuild(Context context) { try {//from w ww . ja v a2 s . c o 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 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); }
From source file:Main.java
public static String getaAppVersion(Context context) { try {/*from ww w . j a v a 2 s . c o m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); return packageInfo.versionName; } catch (NameNotFoundException e) { return null; } }
From source file:Main.java
public static boolean isDebuggableApp(Context context) { int flags;//from www. ja va 2 s. c om try { flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags; } catch (NameNotFoundException e) { flags = 0; e.printStackTrace(); } boolean isDebuggableApp = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); return isDebuggableApp; }