- 导入包
import bundleManager from '@ohos.bundle.bundleManager'
- 同步获取packageName等信息
let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
let PACKAGE_NAME = bundleInfo.name;
let versionName = bundleInfo.versionName;
let versionCode = bundleInfo.versionCode;
let vendor = bundleInfo.vendor;
- 异步获取
bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
.then(bundleInfo => {
let PACKAGE_NAME = bundleInfo.name;
let versionName = bundleInfo.versionName;
let versionCode = bundleInfo.versionCode;
let vendor = bundleInfo.vendor;
})