更新时间:2023-01-10 12:03:25
没有直接获取版本的方法,但有两种解决方法.
There is not a way to directly get the version out, but there are two work-arounds that could be done.
版本可以存储在资源字符串中,并通过以下方式放入清单:
The version could be stored in a resource string, and placed into the manifest by:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.somepackage"
android:versionName="@string/version" android:versionCode="20">
可以创建自定义视图,并将其放入 XML.视图将使用它来分配名称:
One could create a custom view, and place it into the XML. The view would use this to assign the name:
context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
这些解决方案中的任何一个都允许将版本名称放在 XML 中.不幸的是,没有一个很好的简单解决方案,比如 android.R.string.version
或类似的东西.
Either of these solutions would allow for placing the version name in XML. Unfortunately there isn't a nice simple solution, like android.R.string.version
or something like that.