鸿蒙开发WebUrl跳转到手机浏览器

同样直接上代码:

/**
   * @desc : 跳转到外部系统浏览器
   * @author : congge on 2024-04-09 17:02
   **/
  static pushSysWeb(url?:string){
    if (url) {
     try {
       let want = {
         // uncomment line below if wish to implicitly query only in the specific bundle.
         // bundleName: "com.example.myapplication",
         "action": "ohos.want.action.viewData",
         // entities can be omitted.
         "entities": ["entity.system.browsable"],
         "uri": url,
         "type": "text/plain"
       } as Want
       let context = getContext() as common.UIAbilityContext;
       context.startAbility(want)
       console.info(`explicit start ability succeed`)
     } catch (error) {
       console.info(`explicit start ability failed with ${error.code}`)
     }
   }
  }
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐