试图获取包版本信息以在& quot;关于""信息 [英] Trying to get Package Version Information to display in an "About" message
问题描述
我一直在努力从PackageInfo对象类型获取正在运行的应用程序的versionName.
I have been struggling with getting the versionName for a running application from the PackageInfo Object type.
我已经构造了一个Parcelable接口,其中包含与PackageInfo Object类型相关的所有字段.该接口方法的主要输入是一个Parcel对象.
I have constructed a Parcelable Interface with all of the fields associated with the PackageInfo Object type. The primary input for that interface method is a Parcel object.
我似乎无法弄清楚如何正确关联这些Parcelable,Parcel和PackageInfo对象.
I cannot seem to figure out how to correctly associate these Parcelable, Parcel, and PackageInfo objects.
有没有我可以看的示例代码?似乎没有那么困难,但似乎让我很沮丧.
Is there any sample code out there that I can look at? Doesn't seem like it should be that difficult but it seems to be stumping me.
谢谢爵士
推荐答案
示例代码:
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
return packageInfo.versionName;
} catch (NameNotFoundException e) {
//Handle exception
}
这篇关于试图获取包版本信息以在& quot;关于""信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!