get APK Version - Android App

Android examples for App:App Information

Description

get APK 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 {

    public static String getAPKVersion(Context context) {
        String APKVersion = "";
        PackageManager pm = context.getPackageManager();
        String packageName = context.getPackageName();

        PackageInfo info = null;/*w  w  w . j a v  a  2  s . c  om*/
        try {
            info = pm.getPackageInfo(packageName,
                    PackageManager.GET_ACTIVITIES);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        if (info != null) {
            APKVersion = info.versionName + ""; 
        }
        return APKVersion;
    }
}

Related Tutorials