#跟着坚果学鸿蒙#如何拉起应用市场界面
·
如何拉起应用市场界面
开发者可以通过隐式指定want参数中的action为ohos.want.action.appdetail并配置uri为store://appgallery.huawei.com来单独拉起应用市场应用。如需拉起应用市场中某个具体应用的详情页面,开发者需要向uri参数中拼接/app/detail?id=bundleName,其中bundleName为具体需要打开的应用包名,代码参考如下。
import { common, Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; // 拉起应用市场对应的应用详情界面 function startAppGalleryDetailAbility(context: common.UIAbilityContext, bundleName: string): void { let want: Want = { action: 'ohos.want.action.appdetail', uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName, // bundleName为需要打开应用详情的应用的包名 }; context.startAbility(want).then(() => { console.info('Start Ability successfully.'); }).catch((err: BusinessError) => { console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`); }); } @Entry @Component struct StartAppGalleryDetailAbilityView { @State message: string = '拉起应用市场详情页'; build() { Row() { Column() { Button(this.message) .fontSize(24) .fontWeight(FontWeight.Bold) .onClick(() => { const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; const bundleName = 'com.example.xxx'; startAppGalleryDetailAbility(context, bundleName); }) } .width('100%') } .height('100%') } }
完毕
更多推荐
所有评论(0)