get App Version Code - Android android.content.pm

Android examples for android.content.pm:App

Description

get App Version Code

Demo Code

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

public class Main {

  public static int getAppVersionCode(Context context) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packInfo = null;//from  w ww .  j ava2s.com
    try {
      packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
    int code = packInfo.versionCode;
    return code;
  }

}

Related Tutorials