中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
HarmonyOS 如何拉起应用市场?
微信扫码分享
import { BusinessError } from '@kit.BasicServicesKit'; import { common, Want } from '@kit.AbilityKit'; const TAG = '[StoreDemo]'; @Entry @Component struct Index { dialogController: CustomDialogController | null = new CustomDialogController({ builder: RouterDialog({ jumpAppStore: (appid:string) => { this.loadProduct(appid) }, }), autoCancel: true, alignment: DialogAlignment.Bottom, offset: { dx: 0, dy: 0 }, customStyle: true }) build() { Column() { Button('弹窗').onClick(() => { this.dialogController?.open() }) }.justifyContent(FlexAlign.Center) .width('100%') .height('100%') } loadProduct(appid:string) { try { let uri = 'store://appgallery.huawei.com/app' //跳转到应用市场首页 if (appid.length > 0) { uri = `store://appgallery.huawei.com/app/detail?id=${appid}`//跳转到应用市场具体app的详情页 } const request: Want = { uri: uri }; const context = getContext(this) as common.UIAbilityContext; context.startAbility(request).then(()=>{ console.debug('success startAbility') }).catch((err:BusinessError)=>{ console.debug('error startAbility' + err.message) }); } catch (err) { console.error(TAG, `loadProduct failed. code is ${err.code}, message is ${err.message}`); } } } @CustomDialog struct RouterDialog { private controller: CustomDialogController jumpAppStore = (appid: string) => { } build() { Column({space:10}) { Button('跳转应用市场首页') .width(300) .height(50) .onClick(() => { this.jumpAppStore(''); }) Button('跳转某书详情页') .width(300) .height(50) .onClick(() => { this.jumpAppStore('C5765880207852917075'); }) Button('跳转视频详情页') .width(300) .height(50) .onClick(() => { this.jumpAppStore('C1081898888199154560'); }) }.width('100%') .backgroundColor('#ff57ea66') } }