1# Switching from Explicit Want Redirection to Linking Redirection
2
3
4## Overview
5
6Since API version 12, it is not recommended that third-party applications start other applications by specifying an ability (implicit Want mode). Instead, the [linking mode](app-startup-overview.md#application-links) is recommended.
7
8This section describes how to switch from explicit Want mode to linking mode.
9
10## Starting the UIAbility of Another Application
11
121. Install the application on your device. In the [module.json5 file](../quick-start/module-configuration-file.md) of the UIAbility, configure **entities**, **actions**, and **uri** under **skills**.
13    - The **actions** field must contain **ohos.want.action.viewData**.
14    - The **entities** field must contain **entity.system.browsable**.
15    - The **uris** field must contain an element whose **scheme** is **https**. **domainVerify** must be set to **true**. For details about the URI matching rules, see [Matching Rules of uri](explicit-implicit-want-mappings.md#matching-rules-of-uri). If **domainVerify** is set to **true**, domain name verification is enabled. In this case, the target application must pass domain name verification during App Linking. For details about how to configure the App Linking domain name, see [Using App Linking for Application Redirection](app-linking-startup.md).
16
17    ```json
18    {
19      "module": {
20        // ...
21        "abilities": [
22          {
23            // ...
24            "skills": [
25              {
26                "entities": [
27                  "entity.system.browsable"
28                ],
29                "actions": [
30                  "ohos.want.action.viewData"
31                ],
32                "uris": [
33                  {
34                    "scheme": "https",
35                    "host": "www.example.com",
36                  }
37                ],
38              "domainVerify": true
39              }
40            ]
41          }
42        ]
43      }
44    }
45    ```
46
472. Call [openLink](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12) to trigger redirection. The redirected-to link and [options](../reference/apis-ability-kit/js-apis-app-ability-openLinkOptions.md) must be passed in, but the bundle name, module name, and ability name are not required. The system matches the application that meets the skills configuration based on the link.
48    - If **appLinkingOnly** in **options** is set to **true**, the target application must pass domain name verification (Internet connection required). A unique matching item or an unmatched result will be returned.
49    - If **appLinkingOnly** in **options** is set to **false**, the system preferentially attempts to start the target application in App Linking mode. If no matching application is found, the system starts the application in Deep Linking mode.
50
51    For details, see [Using App Linking for Application Redirection](app-linking-startup.md).
52
53    ```ts
54    import { common } from '@kit.AbilityKit';
55    import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions';
56    import { BusinessError } from '@ohos.base';
57    import hilog from '@ohos.hilog';
58
59    const TAG: string = '[UIAbilityComponentsOpenLink]';
60    const DOMAIN_NUMBER: number = 0xFF00;
61
62    @Entry
63    @Component
64    struct Index {
65      build() {
66        Button('start link', { type: ButtonType.Capsule, stateEffect: true })
67          .width('87%')
68          .height('5%')
69          .margin({ bottom: '12vp' })
70          .onClick(() => {
71            let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
72            // let want: Want = {
73            //   bundleName: "com.test.example",
74            //   moduleName: "entry",
75            //   abilityName: "EntryAbility"
76            // };
77            // try {
78            //   context.startAbility(want)
79            //     .then(() => {
80            //       hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.');
81            //     }).catch((err: BusinessError) => {
82            //       hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`);
83            //     })
84            // } catch (paramError) {
85            //   hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, message is ${paramError.message}`);
86            // }
87            let link: string = "https://www.example.com";
88            let openLinkOptions: OpenLinkOptions = {
89              // Specify whether the matched abilities options must pass App Linking domain name verification.
90              appLinkingOnly: true,
91              // Same as parameter in want, which is used to transfer parameters.
92              parameters: {demo_key: "demo_value"}
93            };
94
95            try {
96              context.openLink(link, openLinkOptions)
97                .then(() => {
98                  hilog.info(DOMAIN_NUMBER, TAG, 'open link success.');
99                }).catch((err: BusinessError) => {
100                  hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
101                })
102            } catch (paramError) {
103              hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
104            }
105          })
106      }
107    }
108    ```
109
110## Starting the UIAbility of Another Application and Obtaining the Return Result
111
1121. Install the application on your device. In the [module.json5 file](../quick-start/module-configuration-file.md) of the UIAbility, configure **entities**, **actions**, and **uri** under **skills**.
113
114    - The **actions** field must contain **ohos.want.action.viewData**.
115    - The **entities** field must contain **entity.system.browsable**.
116    - The **uris** field must contain an element whose **scheme** is **https**. **domainVerify** must be set to **true**. For details about the URI matching rules, see [Matching Rules of uri](explicit-implicit-want-mappings.md#matching-rules-of-uri). If **domainVerify** is set to **true**, domain name verification is enabled. In this case, the target application must pass domain name verification during App Linking. For details about how to configure the App Linking domain name, see [Using App Linking for Application Redirection](app-linking-startup.md).
117
118    ```json
119    {
120      "module": {
121        // ...
122        "abilities": [
123          {
124            // ...
125            "skills": [
126              {
127                "entities": [
128                  "entity.system.browsable"
129                ],
130                "actions": [
131                  "ohos.want.action.viewData"
132                ],
133                "uris": [
134                  {
135                    "scheme": "https",
136                    "host": "www.example.com",
137                  }
138                ],
139              "domainVerify": true
140              }
141            ]
142          }
143        ]
144      }
145    }
146    ```
147
1482. Call [openLink](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12) to trigger redirection. The redirected-to link and [options](../reference/apis-ability-kit/js-apis-app-ability-openLinkOptions.md) must be passed in, but the bundle name, module name, and ability name are not required. The system matches the application that meets the skills configuration based on the link. **AbilityResult** is transferred to the callback function through input parameters and returned to the caller application when the ability is terminated. The startup success or failure result is returned through a promise.
149    - If **appLinkingOnly** in **options** is set to **true**, the target application must pass domain name verification (Internet connection required). A unique matching item or an unmatched result will be returned.
150    - If **appLinkingOnly** in **options** is set to **false**, the system preferentially attempts to start the target application in App Linking mode. If no matching application is found, the system starts the application in Deep Linking mode.
151
152    For details, see [Using App Linking for Application Redirection](app-linking-startup.md).
153
154    ```ts
155    import { common } from '@kit.AbilityKit';
156    import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions';
157    import { BusinessError } from '@ohos.base';
158    import hilog from '@ohos.hilog';
159
160    const TAG: string = '[UIAbilityComponentsOpenLink]';
161    const DOMAIN_NUMBER: number = 0xFF00;
162
163    @Entry
164    @Component
165    struct Index {
166      build() {
167        Button('start link', { type: ButtonType.Capsule, stateEffect: true })
168          .width('87%')
169          .height('5%')
170          .margin({ bottom: '12vp' })
171          .onClick(() => {
172            let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
173            // let want: Want = {
174            //   bundleName: "com.test.example",
175            //   moduleName: "entry",
176            //   abilityName: "EntryAbility"
177            // };
178            // try {
179            //   context.startAbilityForResult(want)
180            //     .then((data) => {
181            //       hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success. data:' + JSON.stringify(data));
182            //     }).catch((err: BusinessError) => {
183            //       hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`);
184            //     })
185            // } catch (paramError) {
186            //   hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, message is ${paramError.message}`);
187            // }
188            let link: string = "https://www.example.com";
189            let openLinkOptions: OpenLinkOptions = {
190              // Specify whether the matched abilities options must pass App Linking domain name verification.
191              appLinkingOnly: true,
192              // Same as parameter in want, which is used to transfer parameters.
193              parameters: {demo_key: "demo_value"}
194            };
195
196            try {
197              context.openLink(link, openLinkOptions, (err, data) => {
198                // AbilityResult callback, which is triggered only when the started ability is terminated.
199                hilog.info(DOMAIN_NUMBER, TAG, 'open link success. Callback result:' + JSON.stringify(data));
200              }).then(() => {
201                hilog.info(DOMAIN_NUMBER, TAG, 'open link success.');
202              }).catch((err: BusinessError) => {
203                hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
204              })
205            } catch (paramError) {
206              hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
207            }
208          })
209      }
210    }
211    ```
212