get App Version Code - Android App

Android examples for App:App Information

Description

get App Version Code

Demo Code


//package com.java2s;
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;/*www  . jav a  2 s.  c  om*/
        try {
            packInfo = packageManager.getPackageInfo(
                    context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        int code = packInfo.versionCode;
        return code;
    }
}

Related Tutorials