get App Version by app package - Android android.content.pm

Android examples for android.content.pm:PackageManager

Description

get App Version by app package

Demo Code

import android.content.Context;
import android.content.pm.PackageManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;

public class Main{

    public static String getAppVersion(Context context) {
        try {//from  ww w.j  a v a2 s  .  c o m
            return context.getPackageManager().getPackageInfo(
                    "com.baidu.player", 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

}

Related Tutorials