Android APK Version Get getAppVer(Context context)

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

Description

get App Ver

Declaration

public static String getAppVer(Context context) 

Method Source Code

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.net.wifi.WifiManager;
import android.os.Environment;
import android.preference.PreferenceManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main{
    public static String getAppVer(Context context) {
        try {//from w  ww . ja v  a 2  s  .  c  om
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionName + "(" + packageInfo.versionCode
                    + ")";
        } catch (Throwable e) {
            Logger.w("getPackageInfo failed", e);
            return "";
        }
    }
}

Related

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