HarmonyOS 鸿蒙Next应用提示升级后,如何跳转到应用商店对应应用页面
HarmonyOS 鸿蒙Next应用提示升级后,如何跳转到应用商店对应应用页面
实现逻辑:
基于context.startAbility方法拉起指定应用,并携带参数。其中type是固定配置值,uri是"store://appgallery.huawei.com/app/detail"拼接上id参数,才能拉起鸿蒙应用市场详情页面。
uri: ‘store://appgallery.huawei.com/app/detail?id=’+appId
示例代码1:
import Want from '@ohos.app.ability.Want';
import common from ‘@ohos.app.ability.common’;
@Entry
@Component
struct Index {
@State appId: string = ‘C1142586279411547392’;
controller: TextInputController = new TextInputController();
build() {
Row() {
Column() {
TextInput({ text: this.appId, placeholder: ‘请输入应用的appId’, controller: this.controller })
.width(‘90%’)
.onChange((value: string) => {
this.appId = value
})
Button(‘点击跳转到鸿蒙版应用市场详情页面’)
.margin({top: 50})
.onClick(()=>{
const want: Want = {
uri: store://appgallery.huawei.com/app/detail?id=<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.appId}</span>
};
const context = getContext(this) as common.UIAbilityContext;
context.startAbility(want).then(()=>{
//拉起成功
}).catch(()=>{
// 拉起失败
});
})
}
.width(‘100%’)
}
.height(‘100%’)
}
}
示例代码2:
import { common } from ‘@kit.AbilityKit’;
@Entry
@Component
struct Index {
@State message: string = ‘Hello World’;
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
let context = getContext(this) as common.UIAbilityContext;
context.startAbility({
bundleName: ‘com.huawei.hmos.settings’,
abilityName: ‘com.huawei.hmos.settings.MainAbility’, // com.huawei.hmos.settings.AppInfoAbility
uri: ‘application_info_entry’,
parameters: {
pushParams: ‘com.huawei.hmsapp.appgallery’ // 传入应用市场的包名
}
});
})
}
.width(‘100%’)
}
.height(‘100%’)
}
}
AppID是AGC网站上生成的,可以在AGC上查看对应的APPID;不支持只用包名匹配。
更多关于HarmonyOS 鸿蒙Next应用提示升级后,如何跳转到应用商店对应应用页面的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html