///检测是否存在版本需要更新
import { updateManager } from '@kit.StoreKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import type { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
updateManager.checkAppUpdate(getContext() as common.UIAbilityContext)
.then((checkResult: updateManager.CheckUpdateResult) => {
///checkResult.updateAvailable: 0-不存在更新;1-存在更新
hilog.info(0, 'TAG', "Succeeded in checking Result updateAvailable:" + checkResult.updateAvailable);
}).catch((error: BusinessError) => {
hilog.error(0, 'TAG', `checkAppUpdate onError.code is ${error.code}, message is ${error.message}`);
});
} catch (error) {
hilog.error(0, 'TAG', `checkAppUpdate onError.code is ${error.code}, message is ${error.message}`);
}
///跳转至应用市场相应下载页面
import { productViewManager } from '@kit.StoreKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import type { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
const request: Want = {
parameters: {
// 此处填入要加载的应用包名,例如: bundleName: "com.huawei.hmsapp.appgallery"
bundleName: 'com.xxx'
}
};
productViewManager.loadProduct(getContext(this) as common.UIAbilityContext, request, {
onError: (error: BusinessError) => {
hilog.error(0, 'TAG', `loadProduct onError.code is ${error.code}, message is ${error.message}`);
}
});
} catch (err) {
hilog.error(0, 'TAG', `loadProduct failed.code is ${err.code}, message is ${err.message}`);
}