How to get information about the built-in library version?

I have an eclipse project with two library projects enabled. These projects have their manifest files with version information. Now I want to read the version number from these library projects as part of my main project. Information cannot be read by calling PackageManager:

//Get the version name from the included library project String libVersion = getPackageManager().getPackageInfo("com.google.zxing.client.android", 0).versionName; 

Because the library is not an installed application. But what is the right way to get this information?

For example: I included the zxing Android project as a library project. This project has the following version information in the manifest file:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.zxing.client.android" android:installLocation="auto" android:versionCode="88" android:versionName="4.3.2" > 

I want to read versionCode and versionName. If I use packageManager, as in the above code, I will get versionCode "93" and versionName "4.5".

+6
source share
1 answer

It is actually possible (possibly due to new API changes tested with API 17 (calling project), API 14 (library project)): if you specifically call the correct package name, it will extract version information from this package manifest file:

eg:

 String versionName = getPackageManager(). getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName; 
0
source

Source: https://habr.com/ru/post/956067/


All Articles