未验证 提交 2df1aa80 编写于 作者: zyjhandsome's avatar zyjhandsome 提交者: Gitee

update zh-cn/application-dev/application-models/ability-startup-with-implicit-want.md.

Signed-off-by: zyjhandsome's avatarzyjhandsome <zyjhandsome@126.com>
上级 e11968aa
# 使用隐式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) 当存在多个匹配的应用时,系统将弹出应用选择框供用户选择。示意效果如下图所示。
![stage-want1](figures/stage-want1.png)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册