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