1e41f4b71Sopenharmony_ci# Switching from Explicit Want Redirection to Linking Redirection 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciSince API version 12, you must use Linking to implement cross-application redirection. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## Starting the UIAbility of Another Application 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci1. 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**. 11e41f4b71Sopenharmony_ci - The **actions** field must contain **ohos.want.action.viewData**. 12e41f4b71Sopenharmony_ci - The **entities** field must contain **entity.system.browsable**. 13e41f4b71Sopenharmony_ci - 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). 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci ```json 16e41f4b71Sopenharmony_ci { 17e41f4b71Sopenharmony_ci "module": { 18e41f4b71Sopenharmony_ci // ... 19e41f4b71Sopenharmony_ci "abilities": [ 20e41f4b71Sopenharmony_ci { 21e41f4b71Sopenharmony_ci // ... 22e41f4b71Sopenharmony_ci "skills": [ 23e41f4b71Sopenharmony_ci { 24e41f4b71Sopenharmony_ci "entities": [ 25e41f4b71Sopenharmony_ci "entity.system.browsable" 26e41f4b71Sopenharmony_ci ], 27e41f4b71Sopenharmony_ci "actions": [ 28e41f4b71Sopenharmony_ci "ohos.want.action.viewData" 29e41f4b71Sopenharmony_ci ], 30e41f4b71Sopenharmony_ci "uris": [ 31e41f4b71Sopenharmony_ci { 32e41f4b71Sopenharmony_ci "scheme": "https", 33e41f4b71Sopenharmony_ci "host": "www.example.com", 34e41f4b71Sopenharmony_ci } 35e41f4b71Sopenharmony_ci ], 36e41f4b71Sopenharmony_ci "domainVerify": true 37e41f4b71Sopenharmony_ci } 38e41f4b71Sopenharmony_ci ] 39e41f4b71Sopenharmony_ci } 40e41f4b71Sopenharmony_ci ] 41e41f4b71Sopenharmony_ci } 42e41f4b71Sopenharmony_ci } 43e41f4b71Sopenharmony_ci ``` 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci2. 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. 46e41f4b71Sopenharmony_ci - 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. 47e41f4b71Sopenharmony_ci - 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. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci For details, see [Using App Linking for Application Redirection](app-linking-startup.md). 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci ```ts 52e41f4b71Sopenharmony_ci import { common } from '@kit.AbilityKit'; 53e41f4b71Sopenharmony_ci import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'; 54e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 55e41f4b71Sopenharmony_ci import hilog from '@ohos.hilog'; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci const TAG: string = '[UIAbilityComponentsOpenLink]'; 58e41f4b71Sopenharmony_ci const DOMAIN_NUMBER: number = 0xFF00; 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci @Entry 61e41f4b71Sopenharmony_ci @Component 62e41f4b71Sopenharmony_ci struct Index { 63e41f4b71Sopenharmony_ci build() { 64e41f4b71Sopenharmony_ci Button('start link', { type: ButtonType.Capsule, stateEffect: true }) 65e41f4b71Sopenharmony_ci .width('87%') 66e41f4b71Sopenharmony_ci .height('5%') 67e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 68e41f4b71Sopenharmony_ci .onClick(() => { 69e41f4b71Sopenharmony_ci let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 70e41f4b71Sopenharmony_ci // let want: Want = { 71e41f4b71Sopenharmony_ci // bundleName: "com.test.example", 72e41f4b71Sopenharmony_ci // moduleName: "entry", 73e41f4b71Sopenharmony_ci // abilityName: "EntryAbility" 74e41f4b71Sopenharmony_ci // }; 75e41f4b71Sopenharmony_ci // try { 76e41f4b71Sopenharmony_ci // context.startAbility(want) 77e41f4b71Sopenharmony_ci // .then(() => { 78e41f4b71Sopenharmony_ci // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); 79e41f4b71Sopenharmony_ci // }).catch((err: BusinessError) => { 80e41f4b71Sopenharmony_ci // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`); 81e41f4b71Sopenharmony_ci // }) 82e41f4b71Sopenharmony_ci // } catch (paramError) { 83e41f4b71Sopenharmony_ci // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, message is ${paramError.message}`); 84e41f4b71Sopenharmony_ci // } 85e41f4b71Sopenharmony_ci let link: string = "https://www.example.com"; 86e41f4b71Sopenharmony_ci let openLinkOptions: OpenLinkOptions = { 87e41f4b71Sopenharmony_ci // Specify whether the matched abilities options must pass App Linking domain name verification. 88e41f4b71Sopenharmony_ci appLinkingOnly: true, 89e41f4b71Sopenharmony_ci // Same as parameter in want, which is used to transfer parameters. 90e41f4b71Sopenharmony_ci parameters: {demo_key: "demo_value"} 91e41f4b71Sopenharmony_ci }; 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci try { 94e41f4b71Sopenharmony_ci context.openLink(link, openLinkOptions) 95e41f4b71Sopenharmony_ci .then(() => { 96e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'open link success.'); 97e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 98e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); 99e41f4b71Sopenharmony_ci }) 100e41f4b71Sopenharmony_ci } catch (paramError) { 101e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); 102e41f4b71Sopenharmony_ci } 103e41f4b71Sopenharmony_ci }) 104e41f4b71Sopenharmony_ci } 105e41f4b71Sopenharmony_ci } 106e41f4b71Sopenharmony_ci ``` 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci## Starting the UIAbility of Another Application and Obtaining the Return Result 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci1. 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**. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci - The **actions** field must contain **ohos.want.action.viewData**. 113e41f4b71Sopenharmony_ci - The **entities** field must contain **entity.system.browsable**. 114e41f4b71Sopenharmony_ci - 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). 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci ```json 117e41f4b71Sopenharmony_ci { 118e41f4b71Sopenharmony_ci "module": { 119e41f4b71Sopenharmony_ci // ... 120e41f4b71Sopenharmony_ci "abilities": [ 121e41f4b71Sopenharmony_ci { 122e41f4b71Sopenharmony_ci // ... 123e41f4b71Sopenharmony_ci "skills": [ 124e41f4b71Sopenharmony_ci { 125e41f4b71Sopenharmony_ci "entities": [ 126e41f4b71Sopenharmony_ci "entity.system.browsable" 127e41f4b71Sopenharmony_ci ], 128e41f4b71Sopenharmony_ci "actions": [ 129e41f4b71Sopenharmony_ci "ohos.want.action.viewData" 130e41f4b71Sopenharmony_ci ], 131e41f4b71Sopenharmony_ci "uris": [ 132e41f4b71Sopenharmony_ci { 133e41f4b71Sopenharmony_ci "scheme": "https", 134e41f4b71Sopenharmony_ci "host": "www.example.com", 135e41f4b71Sopenharmony_ci } 136e41f4b71Sopenharmony_ci ], 137e41f4b71Sopenharmony_ci "domainVerify": true 138e41f4b71Sopenharmony_ci } 139e41f4b71Sopenharmony_ci ] 140e41f4b71Sopenharmony_ci } 141e41f4b71Sopenharmony_ci ] 142e41f4b71Sopenharmony_ci } 143e41f4b71Sopenharmony_ci } 144e41f4b71Sopenharmony_ci ``` 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci2. 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. 147e41f4b71Sopenharmony_ci - 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. 148e41f4b71Sopenharmony_ci - 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. 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci For details, see [Using App Linking for Application Redirection](app-linking-startup.md). 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci ```ts 153e41f4b71Sopenharmony_ci import { common } from '@kit.AbilityKit'; 154e41f4b71Sopenharmony_ci import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'; 155e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 156e41f4b71Sopenharmony_ci import hilog from '@ohos.hilog'; 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci const TAG: string = '[UIAbilityComponentsOpenLink]'; 159e41f4b71Sopenharmony_ci const DOMAIN_NUMBER: number = 0xFF00; 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci @Entry 162e41f4b71Sopenharmony_ci @Component 163e41f4b71Sopenharmony_ci struct Index { 164e41f4b71Sopenharmony_ci build() { 165e41f4b71Sopenharmony_ci Button('start link', { type: ButtonType.Capsule, stateEffect: true }) 166e41f4b71Sopenharmony_ci .width('87%') 167e41f4b71Sopenharmony_ci .height('5%') 168e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 169e41f4b71Sopenharmony_ci .onClick(() => { 170e41f4b71Sopenharmony_ci let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 171e41f4b71Sopenharmony_ci // let want: Want = { 172e41f4b71Sopenharmony_ci // bundleName: "com.test.example", 173e41f4b71Sopenharmony_ci // moduleName: "entry", 174e41f4b71Sopenharmony_ci // abilityName: "EntryAbility" 175e41f4b71Sopenharmony_ci // }; 176e41f4b71Sopenharmony_ci // try { 177e41f4b71Sopenharmony_ci // context.startAbilityForResult(want) 178e41f4b71Sopenharmony_ci // .then((data) => { 179e41f4b71Sopenharmony_ci // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success. data:' + JSON.stringify(data)); 180e41f4b71Sopenharmony_ci // }).catch((err: BusinessError) => { 181e41f4b71Sopenharmony_ci // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`); 182e41f4b71Sopenharmony_ci // }) 183e41f4b71Sopenharmony_ci // } catch (paramError) { 184e41f4b71Sopenharmony_ci // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, message is ${paramError.message}`); 185e41f4b71Sopenharmony_ci // } 186e41f4b71Sopenharmony_ci let link: string = "https://www.example.com"; 187e41f4b71Sopenharmony_ci let openLinkOptions: OpenLinkOptions = { 188e41f4b71Sopenharmony_ci // Specify whether the matched abilities options must pass App Linking domain name verification. 189e41f4b71Sopenharmony_ci appLinkingOnly: true, 190e41f4b71Sopenharmony_ci // Same as parameter in want, which is used to transfer parameters. 191e41f4b71Sopenharmony_ci parameters: {demo_key: "demo_value"} 192e41f4b71Sopenharmony_ci }; 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci try { 195e41f4b71Sopenharmony_ci context.openLink(link, openLinkOptions, (err, data) => { 196e41f4b71Sopenharmony_ci // AbilityResult callback, which is triggered only when the started ability is terminated. 197e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'open link success. Callback result:' + JSON.stringify(data)); 198e41f4b71Sopenharmony_ci }).then(() => { 199e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'open link success.'); 200e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 201e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); 202e41f4b71Sopenharmony_ci }) 203e41f4b71Sopenharmony_ci } catch (paramError) { 204e41f4b71Sopenharmony_ci hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); 205e41f4b71Sopenharmony_ci } 206e41f4b71Sopenharmony_ci }) 207e41f4b71Sopenharmony_ci } 208e41f4b71Sopenharmony_ci } 209e41f4b71Sopenharmony_ci ``` 210