Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2df1aa80
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2df1aa80
编写于
4月 06, 2023
作者:
zyjhandsome
提交者:
Gitee
4月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/application-models/ability-startup-with-implicit-want.md.
Signed-off-by:
zyjhandsome
<
zyjhandsome@126.com
>
上级
e11968aa
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
62 addition
and
62 deletion
+62
-62
zh-cn/application-dev/application-models/ability-startup-with-implicit-want.md
.../application-models/ability-startup-with-implicit-want.md
+62
-62
未找到文件。
zh-cn/application-dev/application-models/ability-startup-with-implicit-want.md
浏览文件 @
2df1aa80
# 使用隐式Want打开网址
# 使用隐式Want打开网址
以打开浏览器为例,假设设备上安装了一个或多个浏览器应用。为了使浏览器应用能够正常工作,需要在
[
module.json5配置文件
](
../quick-start/module-configuration-file.md
)
进行配置,具体配置如下:
## 前提条件
设备上安装了一个或多个浏览器。
浏览器应用中通过module.json5配置如下:
```
json
```
json
"skills"
:
[
{
"module"
:
{
//
...
"abilities"
:
[
{
//
...
"skills"
:
[
{
{
"entities"
:
[
"entities"
:
[
"entity.system.home"
,
"entity.system.browsable"
"entity.system.browsable"
//
...
//
...
],
],
"actions"
:
[
"actions"
:
[
"action.system.home"
,
"ohos.want.action.viewData"
"ohos.want.action.viewData"
//
...
//
...
],
],
...
@@ -24,8 +27,7 @@
...
@@ -24,8 +27,7 @@
"host"
:
"www.test.com"
,
"host"
:
"www.test.com"
,
"port"
:
"8080"
,
"port"
:
"8080"
,
//
prefix
matching
//
prefix
matching
"pathStartWith"
:
"query"
,
"pathStartWith"
:
"query"
"type"
:
"text/*"
},
},
{
{
"scheme"
:
"http"
,
"scheme"
:
"http"
,
...
@@ -33,45 +35,43 @@
...
@@ -33,45 +35,43 @@
}
}
//
...
//
...
]
]
},
}
]
]
}
]
}
}
```
```
在调用方UIAbility中,使用隐式Want方式启动浏览器应用。
## 开发步骤
```
ts
import
common
from
'
@ohos.app.ability.common
'
;
1.
在自定义函数implicitStartAbility内使用
**隐式Want**
启动Ability。
function
implicitStartAbility
()
{
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
```
ts
let
wantInfo
=
{
async
implicitStartAbility
()
{
try
{
let
want
=
{
// uncomment line below if wish to implicitly query only in the specific bundle.
// uncomment line below if wish to implicitly query only in the specific bundle.
// bundleName: "com.example.myapplication"
,
// bundleName: 'com.example.myapplication'
,
"
action
"
:
"
ohos.want.action.viewData
"
,
'
action
'
:
'
ohos.want.action.viewData
'
,
// entities can be omitted.
// entities can be omitted.
"
entities
"
:
[
"
entity.system.browsable
"
],
'
entities
'
:
[
'
entity.system.browsable
'
],
"
uri
"
:
"
https://www.test.com:8080/query/student
"
,
'
uri
'
:
'
https://www.test.com:8080/query/student
'
"
type
"
:
"
text/plain
"
}
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
await
context
.
startAbility
(
want
)
console
.
info
(
`explicit start ability succeed`
)
}
catch
(
error
)
{
console
.
info
(
`explicit start ability failed with
${
error
.
code
}
`
)
}
}
}
```
context
.
startAbility
(
wantInfo
).
then
(()
=>
{
// ...
匹配过程如下:
}).
catch
((
err
)
=>
{
1.
want内action不为空,且被skills内action包括,匹配成功。
// ...
})
2.
want内entities不为空,且被skills内entities包括,匹配成功。
}
```
3.
skills内uris拼接为https://www.test.com:8080/query
\*
(
\*
为通配符)包含want内uri,匹配成功。
4.
want内type不为空,且被skills内type包含,匹配成功。
匹配过程分析:
2.
当有多个匹配应用时,会被应用选择器展示给用户进行选择。
1.
调用方传入的want参数的action不为空,待匹配Ability的skills配置中的actions不为空且包含调用方传入的want参数的action,action匹配成功。
2.
调用方传入的want参数的entities不为空,待匹配Ability的skills配置中的entities不为空且包含调用方传入的want参数的entities,entities匹配成功。
3.
待匹配Ability的skills配置中内uris拼接为
`https://www.test.com:8080/query*`
(其中
*
表示通配符),包含调用方传入的want参数的uri,uri匹配成功。
4.
调用方传入的want参数的type不为空,待匹配Ability的skills配置中的type不为空且包含调用方传入的want参数的type,type匹配成功。
!
[
stage-want1
](
figures/stage-want1.png
)
当存在多个匹配的应用时,系统将弹出应用选择框供用户选择。示意效果如下图所示。

编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录