简体   繁体   English

如何从Java下拉AndroidManifest.xml中列出的应用程序版本?

[英]How Do I Pull The Application Version Listed in AndroidManifest.xml From Java?

如何从AndroidManifest.xml中列出应用程序版本从Java, android:versionName专门?

You can use the PackageInfo class. 您可以使用PackageInfo类。 Something along the lines of: 有点像:

PackageInfo myInfo;
myInfo = getPackageManager().getPackageInfo(getPackageName(), 0)
version = myInfo.versionName;

getPackageName() returns the full name of your package (the one that called it). getPackageName()返回包的全名(调用它的名称)。 If you were looking to find version information on a different package, you might want to wrap this in a try {...} catch block, in case the package you were looking for wasn't installed. 如果您希望在不同的软件包上查找版本信息,您可能希望将其包装在try {...} catch块中,以防您没有安装所需的软件包。 There's an example of that here . 有这样一个例子在这里

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

相关问题 如何在AndroidManifest.xml中参数化Activity - How do I parameterize an Activity from within AndroidManifest.xml 如何在Library Project中从AndroidManifest.xml获取版本? - How to get Version from AndroidManifest.xml in a Library Project? 如何解决我的 flutter 应用程序的 androidmanifest.xml 中的此 firebase 消息传递错误? - How do I resolve this firebase messaging error in the androidmanifest.xml of my flutter application? Java / Android:如何访问AndroidManifest.xml中声明的ContentProvider? - Java/Android: how do I access the ContentProvider that is declared in AndroidManifest.xml? 从Java编译androidManifest.xml(Aapt) - Compile androidManifest.xml from Java (aapt) 多 <application> 在AndroidManifest.xml中 - Multiple <application> in AndroidManifest.xml 如何在AndroidManifest.xml中将多个自定义应用程序指定为我的应用程序? - How can i specify more than 1 custom application as my application in AndroidManifest.xml? 如何使用Cordova 3.6.4在AndroidManifest.xml中更改版本代码 - How to change version code in AndroidManifest.xml using Cordova 3.6.4 从应用程序首选项而不是从AndroidManifest.xml读取信息 - Read informations from application preferences instead from AndroidManifest.xml 如何保护AndroidManifest.xml? - How to secure AndroidManifest.xml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM