Obtain app version number - Android Phone

Android examples for Phone:Phone Information

Description

Obtain app version number

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 {

    public static String getVersionName(Context context)
            throws NameNotFoundException {
        PackageManager packageManager = context.getPackageManager();

        PackageInfo packInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        String version = packInfo.versionName;
        return version;
    }//from   w  w  w  . j a  va2s. c om
}

Related Tutorials