Native侧暂无可以获取APP版本信息的接口,如需获取APP版本信息可在ArkTS侧获取,然后传递到Native侧。
通过@kit.AbilityKit模块中的bundleManager查询bundleInfo。在bundleInfo中包含App版本号、版本名信息。
ArkTS侧获取版本信息参考代码如下:
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
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)})
})
}
.width('100%')
}
.height('100%')
}
}