Android APK Version Get getAPKVersion(Context context)

Here you can find the source of getAPKVersion(Context context)

Description

get APK Version

Declaration

public static String getAPKVersion(Context context) 

Method Source Code

//package com.java2s;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class Main {
    public static String getAPKVersion(Context context) {
        String APKVersion = "";
        PackageManager pm = context.getPackageManager();
        String packageName = context.getPackageName();
        PackageInfo info = null;/* w ww. j a v  a  2 s .c om*/
        try {
            info = pm.getPackageInfo(packageName,
                    PackageManager.GET_ACTIVITIES);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        if (info != null) {
            APKVersion = info.versionName + "";
        }
        return APKVersion;
    }
}

Related

  1. getAppVer(Context context)
  2. getAppVersionCode(Context context)
  3. getAppVersionCode(Context context)
  4. getAppVersionName(Context context)