get Package Version Name - Android App

Android examples for App:Package

Description

get Package Version Name

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {
    public static String getVersionName(Context context) {
        return getPackageInfo(context).versionName;
    }/* ww  w  .java2  s . co m*/

    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