HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?

发布于 1周前 作者 gougou168 来自 鸿蒙OS

HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?

具体的问题描述:我想让浏览器帮我打开一个由我指定的网页,怎么操作?


关于HarmonyOS 鸿蒙Next开发中,怎么拉起系统的浏览器,然后传递url?的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

1 回复

可以试试下面的代码:

import common from '@ohos.app.ability.common'

import Want from ‘@ohos.app.ability.Want’

import { BusinessError } from ‘@ohos.base’

function startBrowsableAbility(context: common.UIAbilityContext): void { 

  let want: Want = { 

    action: ‘ohos.want.action.viewData’

    entities: [‘entity.system.browsable’], 

    uri: https://www.huawei.com/ 

  }; 

  context.startAbility(want) 

    .then(() => { 

      console.log(‘success’

    }) 

    .catch((err: BusinessError) => { 

      console.error(Failed to startAbility. Code: ${err.code}, message: ${err.message}); 

    }); 

@Entry 

@Component 

struct BrowsePage { 

  @State message: string = ‘Hello World’

  build() { 

    Row() { 

      Column() { 

        Text(this.message) 

          .fontSize(50

          .fontWeight(FontWeight.Bold) 

          .onClick(() => { 

            const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 

            startBrowsableAbility(context); 

          }) 

      } 

      .width(‘100%’

    } 

    .height(‘100%’

  } 

}<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

回到顶部