[英]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.