HarmonyOS 如何在自己的App中,携带一个网址url启动系统默认浏览器,并通过此系统默认浏览器加载此url?

如题:HarmonyOS 如何在自己的App中,携带一个网址url启动系统默认浏览器,并通过此系统默认浏览器加载此url?

阅读 487
1 个回答

请参考demo

import { common, Want } from '@kit.AbilityKit';

@Entry
@Component
struct liulanqi {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {

        })
      Button("拉起浏览器").onClick(() => {
        let context = getContext(this) as common.UIAbilityContext;
        let want: Want = {
          action: "ohos.want.action.viewData",
          bundleName: 'com.huawei.hmos.browser',
          abilityName: 'MainAbility',
          uri: "https://www.huawei.com/",
        };
        console.log("want", want)
        context.startAbility(want)
      }).margin(10)
    }
    .height('100%')
    .width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏