1# (可选)使用canOpenLink判断应用是否可访问 2## 使用场景 3在应用A想要拉起应用B的场景中,应用A可先调用canOpenLink接口判断应用B是否可访问,如果可访问,再拉起应用B。 4 5> **说明:** 6> 7> canOpenLink接口不支持判断以App Linking方式跳转的目标应用是否安装。 8 9## 约束限制 10在entry模块的module.json5文件中的[querySchemes](../quick-start/module-configuration-file.md)字段中,最多允许配置50个URL scheme。 11## 接口说明 12canOpenLink是[bundleManager](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagercanopenlink12)提供的支持判断目标应用是否可访问的接口。 13匹配规则请参考[显式Want与隐式Want匹配规则](explicit-implicit-want-mappings.md)。 14## 操作步骤 15### 调用方操作步骤 16 171. 在entry模块的module.json5文件中配置[querySchemes](../quick-start/module-configuration-file.md)属性,声明想要查询的URL scheme。 18 19 ```json 20 { 21 "module": { 22 //... 23 "querySchemes": [ 24 "app1Scheme" 25 ] 26 } 27 } 28 ``` 29 302. 导入ohos.bundle.bundleManager模块。 313. 调用canOpenLink接口。 32 33 ```ts 34 import { bundleManager } from '@kit.AbilityKit'; 35 import { BusinessError } from '@kit.BasicServicesKit'; 36 import { hilog } from '@kit.PerformanceAnalysisKit'; 37 try { 38 let link = 'app1Scheme://test.example.com/home'; 39 let canOpen = bundleManager.canOpenLink(link); 40 hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(canOpen)); 41 } catch (err) { 42 let message = (err as BusinessError).message; 43 hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message); 44 } 45 ``` 46 47### 目标方操作步骤 48在module.json5文件中配置[uris](../quick-start/module-configuration-file.md#skills标签)属性。 49 50```json 51{ 52 "module": { 53 //... 54 "abilities": [ 55 { 56 //... 57 "skills": [ 58 { 59 // actions不能为空,actions为空会造成目标方匹配失败 60 "actions": ["ohos.want.action.home"], 61 "uris": [ 62 { 63 "scheme": "app1Scheme", 64 "host": "test.example.com", 65 "pathStartWith": "home" 66 } 67 ] 68 } 69 ] 70 } 71 ] 72 } 73} 74``` 75