Android APK Information Get getAppVersionCode(Context context)

Here you can find the source of getAppVersionCode(Context context)

Description

get App Version Code

Declaration

public static int getAppVersionCode(Context context) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.content.pm.PackageInfo;

import android.content.pm.PackageManager.NameNotFoundException;

public class Main {
    public static int getAppVersionCode(Context context) {
        PackageInfo appPackage = getAppPackage(context);
        return appPackage.versionCode;
    }//  ww w  . j av a 2  s  .  c  o  m

    public static PackageInfo getAppPackage(Context context) {
        PackageInfo appPackage = null;
        try {
            appPackage = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), 0);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return appPackage;
    }
}

Related

  1. isApplicationSentToBackground( final Context context)
  2. restoreToUserApp(Context context)
  3. getApplicationName(Context context)
  4. getAppName(Context context)
  5. getAppPackage(Context context)
  6. getAppVersionName(Context context)
  7. getApkIcon(Context context, String apkPath)