1# 使用隐式Want打开网址 2 3以打开浏览器为例,假设设备上安装了一个或多个浏览器应用。为了使浏览器应用能够正常工作,需要在[module.json5配置文件](../quick-start/module-configuration-file.md)进行配置,具体配置如下: 4 5```json 6{ 7 "module": { 8 ... 9 "abilities": [ 10 { 11 ... 12 "skills": [ 13 { 14 "entities": [ 15 "entity.system.home", 16 "entity.system.browsable" 17 ... 18 ], 19 "actions": [ 20 "action.system.home", 21 "ohos.want.action.viewData" 22 ... 23 ], 24 "uris": [ 25 { 26 "scheme": "https", 27 "host": "www.test.com", 28 "port": "8080", 29 // prefix matching 30 "pathStartWith": "query" 31 }, 32 { 33 "scheme": "http", 34 ... 35 } 36 ... 37 ] 38 } 39 ] 40 } 41 ] 42 } 43} 44``` 45 46在调用方UIAbility中,使用隐式Want方式启动浏览器应用。 47 48```ts 49import common from '@ohos.app.ability.common'; 50import Want from '@ohos.app.ability.Want'; 51import { BusinessError } from '@ohos.base'; 52 53let context = getContext(this) as common.UIAbilityContext; 54let wantInfo: Want = { 55 // uncomment line below if wish to implicitly query only in the specific bundle. 56 // bundleName: 'com.example.myapplication', 57 'action': 'ohos.want.action.viewData', 58 // entities can be omitted. 59 'entities': ['entity.system.browsable'], 60 'uri': 'https://www.test.com:8080/query/student' 61} 62context.startAbility(wantInfo).then(() => { 63 // ... 64}).catch((err: BusinessError) => { 65 // ... 66}) 67``` 68 69匹配过程分析: 70 711. 调用方传入的want参数的action不为空,待匹配目标应用组件的skills配置中的actions不为空且包含调用方传入的want参数的action,action匹配成功。 722. 调用方传入的want参数的entities不为空,待匹配目标应用组件的skills配置中的entities不为空且包含调用方传入的want参数的entities,entities匹配成功。 733. 待匹配目标应用组件的skills配置中内uris拼接为`https://www.test.com:8080/query*`(其中*表示通配符),包含调用方传入的want参数的uri,uri匹配成功。 74 75当存在多个匹配的应用时,系统将弹出应用选择框供用户选择。示意效果如下图所示。 76 77