get App Version - Android App

Android examples for App:App Information

Description

get App Version

Demo Code


//package com.java2s;

import android.content.Context;

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

public class Main {
    private static Context mContext;

    public static String getAppVersion() {
        PackageManager packageManager = mContext.getPackageManager();

        PackageInfo packInfo;//from w w w. j ava  2  s.  co m
        String versionName = "";
        try {
            if (packageManager != null) {
                packInfo = packageManager.getPackageInfo(
                        mContext.getPackageName(), 0);
                if (packInfo != null) {
                    versionName = packInfo.versionName;
                }
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }
}

Related Tutorials