往期鸿蒙全套实战文章必看:(附带鸿蒙全栈学习资料)
如何获取App版本号,版本名,屏幕分辨率等信息
- 通过@kit.AbilityKit中的bundleManager模块查询bundleInfo。在bundleInfo中包含App版本号、版本名信息。
import { BusinessError } from '@kit.BasicServicesKit'; import { bundleManager } from '@kit.AbilityKit'; // ... bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo)=>{ let versionName = bundleInfo.versionName;//应用版本名 let versionNo = bundleInfo.versionCode;//应用版本号 }).catch((error: BusinessError )=>{ console.error("get bundleInfo failed,error is "+error) })
- 在context.config中获取screenDensity,其中包含屏幕分辨率信息。
import { common } from '@kit.AbilityKit'; // ... let context = getContext(this) as common.UIAbilityContext; let screenDensity = context.config.screenDensity;