HarmonyOS 怎么拉起系统的浏览器,并传递url

我想让浏览器替我打开一个由我指定的网页

HarmonyOS
2024-08-02 15:07:21
浏览
收藏 0
回答 1
回答 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%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
分享
微博
QQ
微信
回复
2024-08-02 20:24:09
相关问题
浏览器应用应该怎样拉起
1198浏览 • 2回复 待解决
HarmonyOS 浏览器不能通过scheme拉起app
1636浏览 • 1回复 待解决
有谁知道如何拉起浏览器应用
2449浏览 • 1回复 待解决
HarmonyOS 浏览器访问H5,唤起App
1038浏览 • 1回复 待解决
HarmonyOS 启动默认浏览器
1515浏览 • 1回复 待解决
服务卡片webview如何跳转系统浏览器
8861浏览 • 2回复 待解决
HarmonyOS跳转系统浏览器打开网页报错
1846浏览 • 1回复 待解决
HarmonyOS webview浏览器获取定位异常
950浏览 • 1回复 待解决
HarmonyOS 如何在浏览器唤起app
1702浏览 • 1回复 待解决