试图让软件包版本信息显示在[关于"信息信息、软件包、版本、QUOT

2023-09-05 10:47:43 作者:撒旦の黒名单

我一直在努力与获得的VERSIONNAME从PackageInfo对象类型运行的应用程序。

I have been struggling with getting the versionName for a running application from the PackageInfo Object type.

我已经建立了一个Parcelable接口与所有的PackageInfo对象类型相关的字段。该接口方法的主要投入是一个包裹对象。

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,包裹和PackageInfo对象。

I cannot seem to figure out how to correctly associate these Parcelable, Parcel, and PackageInfo objects.

有什么样code,在那里,我可以看看?似乎并不像它应该是困难的,但它似乎是绊倒了我。

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.

谢谢 爵士

推荐答案

样品code:

try {
    PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    return packageInfo.versionName;
} catch (NameNotFoundException e) {
    //Handle exception
}