HarmonyOS 如何跳转到系统默认浏览器,并打开传入的url?

如何跳转到系统默认浏览器,并打开传入的url。

HarmonyOS
2024-11-21 10:43:02
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考如下代码:

import common from '@ohos.app.ability.common'; 
import Want from '@ohos.app.ability.Want'; 
import { BusinessError } from '@ohos.base'; 
function startBrowsableAbility(context: common.UIAbilityContext,myurl:string): void { 
  let want: Want = { 
    action: 'ohos.want.action.viewData', 
    entities: ['entity.system.browsable'], 
    uri: myurl 
  }; 
  context.startAbility(want).then(() => { 
    console.log('success') 
  }).catch((err: BusinessError) => { 
    console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`); 
  }); 
} 
@Entry 
@Component 
struct routeExample { 
  build() { 
    Column(){ 
      Button('系统浏览器打开页面') 
        .onClick(() => { 
          let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 
          let myurl = 'https://www.huawei.com/'; 
          startBrowsableAbility(context,myurl); 
        }) 
    }.width('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.
分享
微博
QQ
微信
回复
2024-11-21 16:56:50
相关问题
HarmonyOS跳转系统浏览器打开网页报错
1628浏览 • 1回复 待解决
HarmonyOS applink从浏览器跳转到应用
982浏览 • 1回复 待解决
HarmonyOS 跳转到外部浏览器固定链接
788浏览 • 1回复 待解决
HarmonyOS 启动默认浏览器
1329浏览 • 1回复 待解决
服务卡片webview如何跳转系统浏览器
8528浏览 • 2回复 待解决
安卓App或者浏览器如何跳转鸿蒙App
10528浏览 • 1回复 待解决
HarmonyOS 浏览器访问H5,唤起App
836浏览 • 1回复 待解决