get Package Version Code - Android App

Android examples for App:Package

Description

get Package 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 getVersionCode(Context context) {
        return getPackageInfo(context).versionCode;
    }//from   www .j  a va 2  s.  c om

    private static PackageInfo getPackageInfo(Context context) {
        PackageInfo pi = null;

        try {
            PackageManager pm = context.getPackageManager();
            pi = pm.getPackageInfo(context.getPackageName(),
                    PackageManager.GET_CONFIGURATIONS);

            return pi;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return pi;
    }
}

Related Tutorials