HarmonyOS 鸿蒙Next 调用浏览器打开网址报错“暂无支持此类文件的应用”
HarmonyOS 鸿蒙Next 调用浏览器打开网址报错“暂无支持此类文件的应用”
按照文档要求,使用隐式Want打开浏览器。报错“暂无支持此类文件的应用”
调用方式:
/**
* 打开浏览器
* @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…
})
}
配置文件:
“skills”: [
{
“entities”: [
“entity.system.home”,
“entity.system.browsable” // 浏览器打开
],
“actions”: [
“action.system.home”,
“ohos.want.action.viewData” // 浏览器打开
]
}
]
调用方式:
/**
* 打开浏览器
* @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…
})
}
配置文件:
“skills”: [
{
“entities”: [
“entity.system.home”,
“entity.system.browsable” // 浏览器打开
],
“actions”: [
“action.system.home”,
“ohos.want.action.viewData” // 浏览器打开
]
}
]
更多关于HarmonyOS 鸿蒙Next 调用浏览器打开网址报错“暂无支持此类文件的应用”的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
兄弟,你的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.baidu.com",
"port": "8080",
// prefix matching
"pathStartWith": "query",
}
]
}
]
index文件
import common from '[@ohos](/user/ohos).app.ability.common';
import Want from '[@ohos](/user/ohos).app.ability.Want';
import { BusinessError } from '[@ohos](/user/ohos).base';
import process from '[@ohos](/user/ohos).process';
let context = getContext(this) as common.UIAbilityContext;
let wantInfo: Want = {
"action": 'ohos.want.action.viewData',
"entities": ['entity.system.browsable'],
"uri": "https://www.baidu.com",
}
[@Entry](/user/Entry)
[@Component](/user/Component)
struct Index {
[@State](/user/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%')
}
}
<p><span>参考文档:‘<a class="autoSetLinkTag" href="https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/explicit-implicit-want-mappings-V13" target="_blank">https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/explicit-implicit-want-mappings-V13</a>’</span></p> <p></p> <p>匹配过程分析:<br> <br> 调用方传入的want参数的action不为空,待匹配目标应用组件的skills配置中的actions不为空且包含调用方传入的want参数的action,action匹配成功。<br> 调用方传入的want参数的entities不为空,待匹配目标应用组件的skills配置中的entities不为空且包含调用方传入的want参数的entities,entities匹配成功。<br><span> 待匹配目标应用组件的skills配置中内uris拼接为<a class="autoSetLinkTag" href="https://www.test.com:8080/query" target="_blank" rel="nofollow">https://www.test.com:8080/query</a>*(其中*表示通配符),包含调用方传入的want参数的uri,uri匹配成功。</span></p>
更多关于HarmonyOS 鸿蒙Next 调用浏览器打开网址报错“暂无支持此类文件的应用”的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html