简体   繁体   English

在Android中检索该应用的版本代码

[英]Retrieve the version code of the App in Android

How can I retrieve the version code of my application programmatically? 如何以编程方式检索应用程序的版本代码?

I checked that question but all the links are broken 我检查了这个问题,但是所有链接都坏了

Thanks 谢谢

try {
    ComponentName comp = new ComponentName(this, [CURRENT_ACTIVITY].class);
    PackageInfo pinfo = getPackageManager().getPackageInfo(comp.getPackageName(), 0);

    int versionCode = pinfo.versionCode;

} catch(android.content.pm.PackageManager.NameNotFoundException e) {}

Replace "[CURRENT_ACTIVITY]" with the actual name of your activity. 用活动的实际名称替换“ [CURRENT_ACTIVITY]”。 (Just to clarify haha) (只是为了澄清哈哈)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中检索应用包和版本 - Retrieve the app package and version in Android APK的不同版本代码,带有phonegap构建的Android应用程序 - Different version code for APK, android app with phonegap build Android应用程序支持的设备是否取决于所编写代码的Java版本? - Do supported devices for an android app depends on Java version the code written in? 如果我要在1.0版本中编写它,那么在更新android应用程序时应该写什么版本代码和版本名称? - What should I write in version code and version name while updating an android app if I fogot to write it in the 1.0 version? 较低版本的应用未在android的较高版本中运行 - Lower version app not running in the Higher version in android Android App无法在更高版本上运行 - Android App not running on higher version Android应用程式无法在版本19上运作 - Android app not working on version 19 相同的Android列表视图代码在一个版本的应用程序中滚动不稳定,其他则不是。 (已知的调整) - The same Android listview code is choppy on scroll in one version of app, in other is not. (known tweaks performed) 我的 Android 应用程序不支持 Android 版本 9 - My Android app not supporting Android version 9 在代码中从 maven pom.xml 中检索版本 - Retrieve version from maven pom.xml in code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM