Android APK Version Get getAppVersionCode(Context context)

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

Description

get App Version Code

License

Open Source License

Declaration

public static int getAppVersionCode(Context context) 

Method Source Code

//License from project: Open Source License 

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Looper;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.webkit.URLUtil;

public class Main{
    static final String TAG = AndroidUtil.class.getSimpleName();
    public static int getAppVersionCode(Context context) {
        int versionCode = 0;
        try {//from ww  w  .j a  v  a2 s .  co m
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionCode = pi.versionCode;
        } catch (Exception e) {
            FrameworkLog.e(TAG,
                    "getAppVersionCode Exception: " + e.getMessage());
        }
        return versionCode;
    }
}

Related

  1. getAPKVersion(Context context)
  2. getAppVer(Context context)
  3. getAppVersionCode(Context context)
  4. getAppVersionName(Context context)
  5. getAppVersionName(Context context, String defVersion)
  6. getApplicationVersion(Context ctx)