• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# (Optional) Using canOpenLink to Check Application Accessibility
2## When to Use
3Before starting application B, application A can call **canOpenLink** to check whether application B is accessible.
4## Constraints
5A maximum of 50 URL schemes can be configured in the [querySchemes](../quick-start/module-configuration-file.md) field in the **module.json5** file of the entry module.
6## Available APIs
7**canOpenLink** is provided by the [bundleManager](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagercanopenlink12) module to check whether a target application is accessible.
8
9For details about the matching rules, see [Matching Rules of Explicit Want and Implicit Want](explicit-implicit-want-mappings.md).
10
11## How to Develop
12### Procedure for the Caller Application
13
141. Configure the [querySchemes](../quick-start/module-configuration-file.md) field in the **module.json5** file of the entry module to declare the URL schemes.
15
16    ```json
17    {
18      "module": {
19        //...
20        "querySchemes": [
21          "app1Scheme"
22        ]
23      }
24    }
25    ```
26
272. Import the **ohos.bundle.bundleManager** module.
283. Call **canOpenLink**.
29
30    ```ts
31    import { bundleManager } from '@kit.AbilityKit';
32    import { BusinessError } from '@kit.BasicServicesKit';
33    import { hilog } from '@kit.PerformanceAnalysisKit';
34    try {
35      let link = 'app1Scheme://test.example.com/home';
36      let canOpen = bundleManager.canOpenLink(link);
37      hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(canOpen));
38    } catch (err) {
39      let message = (err as BusinessError).message;
40      hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
41    }
42    ```
43
44### Procedure for the Target Application
45Configure the [uris](../quick-start/module-configuration-file.md#skills) field in the **module.json5** file.
46
47```json
48{
49  "module": {
50    //...
51    "abilities": [
52      {
53        //...
54        "skills": [
55          {
56            "uris": [
57              {
58                "scheme": "app1Scheme",
59                "host": "test.example.com",
60                "pathStartWith": "home"
61              }
62            ]
63          }
64        ]
65      }
66    ]
67  }
68}
69```
70