Android Utililty Methods APK Version Get

List of utility methods to do APK Version Get

Description

The list of methods to do APK Version Get are organized into topic(s).

Method

StringgetAPKVersion(Context context)
get APK Version
String APKVersion = "";
PackageManager pm = context.getPackageManager();
String packageName = context.getPackageName();
PackageInfo info = null;
try {
    info = pm.getPackageInfo(packageName,
            PackageManager.GET_ACTIVITIES);
} catch (NameNotFoundException e) {
...
StringgetAppVer(Context context)
get App Ver
try {
    PackageInfo packageInfo = context.getPackageManager()
            .getPackageInfo(context.getPackageName(), 0);
    return packageInfo.versionName + "(" + packageInfo.versionCode
            + ")";
} catch (Throwable e) {
    Logger.w("getPackageInfo failed", e);
    return "";
...
intgetAppVersionCode(Context context)
get App Version Code
int versionCode = 0;
try {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
    versionCode = pi.versionCode;
} catch (Exception e) {
    FrameworkLog.e(TAG,
            "getAppVersionCode Exception: " + e.getMessage());
...
intgetAppVersionCode(Context context)
Returns version code of OpenSudoku.
try {
    return context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
    throw new RuntimeException(e);
StringgetAppVersionName(Context context)
Returns version name of OpenSudoku.
try {
    return context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
    throw new RuntimeException(e);
StringgetAppVersionName(Context context, String defVersion)
get App Version Name
String versionName = defVersion;
try {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
    versionName = pi.versionName;
    if (versionName == null || versionName.length() <= 0) {
        return defVersion;
} catch (Exception e) {
    FrameworkLog.e(TAG,
            "getAppVersionName Exception: " + e.getMessage());
return versionName;
StringgetApplicationVersion(Context ctx)
Returns the application version from manifest file
String version = null;
try {
    PackageInfo info = ctx.getPackageManager().getPackageInfo(
            ctx.getPackageName(), 0);
    version = info.versionName;
} catch (NameNotFoundException e) {
return version;
...
longgetFirstInstalled()
get First Installed
long firstInstalled = 0;
PackageManager pm = myApp.getPackageManager();
try {
    PackageInfo pi = pm.getPackageInfo(myApp
            .getApplicationContext().getPackageName(),
            pm.GET_SIGNATURES);
    try {
        try {
...
StringgetVersion(Context context)
get Version
try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0);
    return pInfo.versionName + " :: " + pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
    return "unknown";
StringgetVersionCode(Context context)
get Version Code
try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0);
    return "" + pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
    return "unknown";