AndroidManifest.xml中的code用户VERSIONNAME值 [英] User versionName value of AndroidManifest.xml in code

查看:115
本文介绍了AndroidManifest.xml中的code用户VERSIONNAME值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的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;

这篇关于AndroidManifest.xml中的code用户VERSIONNAME值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆