从 Android 应用程序内部查询版本代码

huangapple go评论61阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月6日 03:25:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定