AndroidManifest.xml中的code用户VERSIONNAME值用户、xml、AndroidManifest、VERSIONNAME

2023-09-03 20:54:12 作者:小祖宗

的Andr​​oidManifest.xml 包含应用程序的版本名称,像

The AndroidManifest.xml contains the version name of the application, something like

android:versionName="1.0"

现在的问题 - 是它在某种程度上可以访问此版本名称中的源$ C ​​$ C,这样我就可以显示出来,例如在关于对话框

Now the question - is it somehow possible to access this version name in the source code, so that I can display it for example in an About Dialog?

推荐答案

如果您使用ADT和Eclipse:

If you use ADT and Eclipse:

String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

如果您使用的摇篮,还有一个更简单的方法,因为它把数据放入BuildConfig你:

If you use Gradle, there is an easier way, since it puts the data into BuildConfig for you:

String version = BuildConfig.VERSION_NAME;