问题
I have an eclipse project with two included library projects. These projects have their own manifest files with version information. Now I want to read the version number from these library projects within my main project. The information can't be read by calling the 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's the right way to get these information?
For instance: I have included zxing Android project as library project. These Project has following version information in its 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 like in the coding above, I will get versionCode "93" and versionName "4.5".
回答1:
In fact it is possible now (maybe 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 retrieve version information from that packages Manifest file:
eg:
String versionName = getPackageManager().
getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName;
来源:https://stackoverflow.com/questions/19399837/how-to-get-version-information-of-an-included-library