get App Version Name - Android App

Android examples for App:App Information

Description

get App Version Name

Demo Code


//package com.java2s;

import android.content.Context;

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

import android.util.Log;

public class Main {
    private static final String TAG = "ActivityUtils";

    public static String getAppVersionName(Context context) {
        String versionName = "";
        try {//from  ww w .  j  a v  a  2s.  c o  m
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception", e);
        }
        return versionName;
    }
}

Related Tutorials