14

I would like to know how to read installed apk version. For example, from my app i would like to know what version of Skype is installed on my phone.

To Read my app version i use:

PackageInfo pinfo = null;
pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String versionName = pinfo.versionName;

Of course with try/catch surrounded.

Dim
  • 4,527
  • 15
  • 80
  • 139
  • For android 11, you need to define specific **package** in android manifest or if your app has need to get All packages, then you would need to add `android.permission.QUERY_ALL_PACKAGES` permission. But with this permission going to play store, you need to make sure that your app complies the policy: [https://developer.android.com/about/versions/11/privacy/package-visibility#all-apps] – Zeeshan Shahid Aug 04 '21 at 07:37

3 Answers3

18

You need to figure out what is the right package name of the skype installed on your device.

PackageInfo pinfo = null;
pinfo = getPackageManager().getPackageInfo("com.skype.android", 0);

//getVersionCode is Deprecated, instead use getLongVersionCode().
long verCode = pinfo.getLongVersionCode();
//getVersionName is Deprecated, instead use versionName
String verName = pinfo.versionName;

You can get all packages and find out name with the following method call:

List<PackageInfo> packages = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
Community
  • 1
  • 1
Maxim
  • 4,152
  • 8
  • 50
  • 77
  • 2
    I did not see methods like pinfo.getVersionCode() or pinfo.getVersionName(). Please see my answer at the bottom for working code. – Sileria Aug 30 '16 at 02:46
  • 1
    @Mobistry to see that you should look back into 2012. – Maxim Aug 30 '16 at 15:42
3

This worked for me:

PackageInfo pinfo = context.getPackageManager().getPackageInfo( "com.myapp", 0 );
String verName = pinfo.versionName;
int verCode = pinfo.versionCode;
Sileria
  • 15,223
  • 4
  • 49
  • 28
3

You should be able do this using something like this:

List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);

PackageInfo mypackage = <get required app from the list>;

String versionName = mypackage.versionName;
int versionCode = mypackage.versionCode;

Have a look at PackageInfo class.

Aleks G
  • 56,435
  • 29
  • 168
  • 265