电子说
以打开浏览器为例,假设设备上安装了一个或多个浏览器应用。为了使浏览器应用能够正常工作,需要在[module.json5配置文件]进行配置,具体配置如下: 开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
{
"module": {
"abilities": [
{
// 入口配置
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
},
// 浏览器配置
{
"actions": [
"ohos.want.action.viewData"
],
"entities": [
"entity.system.browsable"
],
"uris": [{
"scheme": "https",
"host": "www.test.com",
"port": "8080",
"pathStartWith": "query"
},
{
"scheme": "http"
}
]
}
]
}
]
}
}
在调用方UIAbility中,使用隐式Want方式启动浏览器应用。
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let context = getContext(this) as common.UIAbilityContext;
let wantInfo: 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: 'https://www.test.com:8080/query/student'
}
context.startAbility(wantInfo).then(() = > {
// ...
}).catch((err: BusinessError) = > {
// ...
})
匹配过程分析:
https://www.test.com:8080/query*
(其中*表示通配符),包含调用方传入的want参数的uri,uri匹配成功。当存在多个匹配的应用时,系统将弹出应用选择框供用户选择。示意效果如下图所示。
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !