how to get current application version code in android code example

Example 1: get app version android

String versionName = context.getPackageManager()
    .getPackageInfo(context.getPackageName(), 0).versionName;

Example 2: current app version check in android

private String getCurrentVersion(){
PackageManager pm = this.getPackageManager();
PackageInfo pInfo = null;

        try {
            pInfo =  pm.getPackageInfo(this.getPackageName(),0);

        } catch (PackageManager.NameNotFoundException e1) {
            e1.printStackTrace();
        }
        String currentVersion = pInfo.versionName;

        return currentVersion;
    }

Tags:

Java Example