HarmonyOS 调用浏览器打开网址,弹窗报错“暂无支持此类文件的应用”

调用方式:

/** 
 * 打开浏览器 
 * @param url 
 */ 
startBrowser(context: Context, url: string) { 
  let uiContext = context as common.UIAbilityContext 
  let wantInfo: Want = { 
    action: 'ohos.want.action.viewData', 
    entities: ['entity.system.browsable'], 
    uri: url 
  } 
  uiContext.startAbility(wantInfo).then(() => { 
    // do nothing... 
  }).catch((err: BusinessError) => { 
    // do nothing... 
  }) 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

配置文件:

"skills": [ 
{ 
  "entities": [ 
  "entity.system.home", 
  "entity.system.browsable" // 浏览器打开 
  ], 
  "actions": [ 
  "action.system.home", 
  "ohos.want.action.viewData" // 浏览器打开 
  ] 
} 
]
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
HarmonyOS
2024-11-05 12:00:51
1712浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

module.json5文件有问题,没有uris参数。可以参考一下demo:

//module.json5文件中的skills: 
"skills": [ 
{ 
  "entities": [ 
  "entity.system.home", 
  "entity.system.browsable" 
  ], 
  "actions": [ 
  "action.system.home", 
  "ohos.want.action.viewData" 
  ], 
  "uris": [ 
  { 
    "scheme": "https", 
  "host": "www.huawei.com", 
  "port": "8080", 
  // prefix matching 
  "pathStartWith": "query", 
  } 
  ] 
} 
] 
 
//index文件 
//want 拉起系统浏览器 
 
import common from '@ohos.app.ability.common'; 
import Want from '@ohos.app.ability.Want'; 
import { BusinessError } from '@ohos.base'; 
import process from '@ohos.process'; 
 
 
let context = getContext(this) as common.UIAbilityContext; 
let wantInfo: Want = { 
 
  "action": 'ohos.want.action.viewData', 
  "entities": [ 'entity.system.browsable' ], 
  "uri": "https://www.huawei.com", 
} 
 
 
 
@Entry 
@Component 
struct Index { 
  @State message: string = '跳转'; 
  aboutToAppear(): void { 
    console.log("child-testTAG",`${process.tid}`) 
  } 
 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(async ()=>{ 
            context.startAbility(wantInfo).then(() => { 
              // ... 
            }).catch((err: BusinessError) => { 
              // ... 
            }) 
          }) 
      } 
      .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.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ability-startup-with-implicit-want-V5

文档中重点看匹配过程分析:

调用方传入的want参数的action不为空,待匹配目标应用组件的skills配置中的actions不为空且包含调用方传入的want参数的action,action匹配成功。

待匹配目标应用组件的skills配置中内uris拼接为https://www.test.com:8080/query*(其中*表示通配符),包含调用方传入的want参数的uri,uri匹配成功。​

分享
微博
QQ
微信
回复
2024-11-05 15:09:41
相关问题
HarmonyOS跳转系统浏览器打开网报错
1857浏览 • 1回复 待解决
Web组件是否支持浏览器localstorage?
1635浏览 • 1回复 待解决
浏览器应用应该怎样拉起?
1205浏览 • 2回复 待解决
浏览器下载文件如何导入鸿蒙
8585浏览 • 1回复 待解决