get App Version Name - Android android.content.pm

Android examples for android.content.pm:App

Description

get App Version Name

Demo Code

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static String getAppVersionName(Context context) {

    PackageManager packageManager = context.getPackageManager();
    PackageInfo packInfo = null;/*  w w w .j  ava 2s .  c  o m*/
    try {
      packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
    String version = packInfo.versionName;

    return version;
  }

}

Related Tutorials