首先通过@ohos.bundle.bundleManager模块bundleManager.getBundleInfoForSelf()接口获取包信息BundleInfo,然后分别通过BundleInfo.versionCode、BundleInfo.versionName获取所需信息。import bundleManager from '@ohos.bundle.bundleManager'; import hilog from '@ohos.hilog'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { const versionCode = data.versionCode; const versionName = data.versionName; hilog.info(0x0000, 'testTag', `successfully. versionCode: ${versionCode}, versionName: ${versionName}`); }).catch(err => { hilog.error(0x0000, 'testTag', 'failed. Cause: %{public}s', err.message); }); } catch (err) { hilog.error(0x0000, 'testTag', 'failed: %{public}s', err.message); }参考链接getBundleInfoForSelf
首先通过@ohos.bundle.bundleManager模块bundleManager.getBundleInfoForSelf()接口获取包信息BundleInfo,然后分别通过BundleInfo.versionCode、BundleInfo.versionName获取所需信息。
参考链接
getBundleInfoForSelf