英文:
Query version code from inside an Android app
问题
如何从应用程序内部查询versionCode
(如清单中声明的)?
应该很容易(人们可能会认为),但在Android API的常见选择中,似乎唯一具有这种信息的是PackageInfo
,可以通过PackageManager
获得,需要明确指定包名。
是否有更简单的方法来获取正在运行的应用程序的版本代码?
英文:
How can I query the versionCode
(as declared in the manifest) from inside the app itself?
Should be easy enough (one might think), but of the usual suspects in the Android API, the only one that seems to have this kind of information is PackageInfo
, which can be obtained through PackageManager
, requiring me to explicitly specify the package.
Is there an easier way to specifically get the version code of the running app?
答案1
得分: 1
"Registering Version code in the Manifest is deprecated, it kept in gradle script and injected into BuildConfig while building the APK/AAB. So, you can generate and use BuildConfig.VERSION_CODE
field."
(在清单中注册版本代码已被弃用,它保存在Gradle脚本中,并在构建APK/AAB时注入到BuildConfig中。因此,您可以生成并使用BuildConfig.VERSION_CODE
字段。)
英文:
Registering Version code in the Manifest is deprecated, it kept in gradle script and injected into BuildConfig while building the APK/AAB. So, you can generate and use BuildConfig.VERSION_CODE
field
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论