如何获得包括图书馆的版本信息? [英] How to get version information of an included library?
问题描述
我有两个Eclipse项目包括库项目。这些项目都有自己的清单文件与版本信息。现在,我想我的主要项目中读这些库项目的版本号。该信息无法通过调用软件包管理系统读取:
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?
例如:我已经包括zxing Android项目的库项目。这些项目具有以下的清单文件版本信息:
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" >
我想读的版本code和的versionName。如果我在编码使用的软件包管理系统上面的一样,我会得到版本code93和的versionName4.5。
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".
推荐答案
在事实上,它的是现在可能的(可能是由于新的API变化,API 17(主叫项目),API 14测试(库项目)):如果你专门调用正确的软件包名称会检索该版本的信息,打包清单文件:
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:
例如:
String versionName = getPackageManager().
getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName;
这篇关于如何获得包括图书馆的版本信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!