How can I get programmatically version code or version name of apk from AndroidManifest.xml file after download and without installing it.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xx.xxx"
android:versionCode="1"
android:versionName="1.1" >
For example I want to check if a new version is uploaded on my IIS service after that install it on device, if not a new version I don't want to install it.
For the upgrade scenario specifically an alternative approach might be to have a web service that delivers the current version number and check that instead of downloading the entire apk just to check its version. It would save some bandwidth, be a little more performant (much faster to download than an apk if the whole apk isn't needed most of the time) and much simpler to implement.
In the simplest form you could have a simple text file on your server...
http://some-place.com/current-app-version.txt
Inside of that text file have something like
and then download that file and check against the currently installed version.
Building a more advanced solution to that would be to implement a proper web service and have an api call at launch which could return some json, i.e.
http://api.some-place.com/versionCheck
:If you are using version 2.2 and above of Android Studio then in Android Studio use Build → Analyze APK then select AndroidManifest.xml file.
Following worked for me from the command line:
NOTE: aapt.exe is found in a
build-tools
sub-folder of SDK. For example:I can now successfully retrieve the version of an APK file from its binary XML data.
This topic is where I got the key to my answer (I also added my version of Ribo's code): How to parse the AndroidManifest.xml file inside an .apk package
Additionally, here's the XML parsing code I wrote, specifically to fetch the version:
XML Parsing
Version Comparison (seen as SystemPackageTools.compareVersions in previous snippet) NOTE: This code is inspired from the following topic: Efficient way to compare version strings in Java
I hope this helps.