Native侧目前没有获取APP版本信息的接口。如需获取APP版本信息,可以在ArkTS侧获取,然后传递到Native侧。
通过@kit.AbilityKit模块中的bundleManager查询bundleInfo。bundleInfo包含App版本号和版本名。
ArkTS侧传递数据到Native侧可参考链接:
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;//Application version name
let versionNo = bundleInfo.versionCode;//Application version number
}).catch((error : BusinessError)=>{
console.error("get bundleInfo failed,error is "+error)})
})
}
.width('100%')
}
.height('100%')
}
} ArkTS侧传递数据到Native侧可参考链接:
获取模块相关信息参考链接: