1# @ohos.app.ability.OpenLinkOptions (OpenLinkOptions) 2 3**OpenLinkOptions** can be used as an input parameter of [openLink()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12) to indicate whether to enable only App Linking and pass in optional parameters in the form of key-value pairs. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10 11## Modules to Import 12 13```ts 14import { OpenLinkOptions } from '@kit.AbilityKit'; 15``` 16 17## Properties 18 19**Atomic service API**: This API can be used in atomic services since API version 12. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23| Name| Type| Read Only| Optional| Description| 24| -------- | -------- | -------- | -------- | -------- | 25| appLinkingOnly | boolean | No| Yes| Whether the UIAbility must be started in App Linking mode.<br>- If this parameter is set to **true** and no UIAbility matches the URL in App Linking, the result is returned directly.<br>- If this parameter is set to **false** and no UIAbility matches the URL in App Linking, App Linking is degraded to Deep Link. The default value is **false**.<br>When the aa command is used to implicitly start an ability, you can set **--pb appLinkingOnly true** or **--pb appLinkingOnly false** to start the ability in App Linking mode.| 26| parameters | Record\<string, Object> | No| Yes| List of parameters in Want.| 27 28**Example** 29 30 ```ts 31 import { common, OpenLinkOptions } from '@kit.AbilityKit'; 32 import { hilog } from '@kit.PerformanceAnalysisKit'; 33 import { BusinessError } from '@kit.BasicServicesKit'; 34 35 const DOMAIN = 0xeeee; 36 const TAG: string = '[openLinkDemo]'; 37 38 @Entry 39 @Component 40 struct Index { 41 @State message: string = 'I am caller'; 42 43 build() { 44 Row() { 45 Column() { 46 Text(this.message) 47 .fontSize(50) 48 .fontWeight(FontWeight.Bold) 49 Button('start browser', { type: ButtonType.Capsule, stateEffect: true }) 50 .width('87%') 51 .height('5%') 52 .margin({ bottom: '12vp' }) 53 .onClick(() => { 54 let context = getContext(this) as common.UIAbilityContext; 55 let link: string = 'https://www.example.com'; 56 let openLinkOptions: OpenLinkOptions = { 57 appLinkingOnly: true, 58 parameters: { demo_key: 'demo_value' } 59 }; 60 try { 61 context.openLink( 62 link, 63 openLinkOptions, 64 (err, result) => { 65 hilog.error(DOMAIN, TAG, `openLink callback error.code: ${JSON.stringify(err)}`); 66 hilog.info(DOMAIN, TAG, `openLink callback result: ${JSON.stringify(result.resultCode)}`); 67 hilog.info(DOMAIN, TAG, `openLink callback result data: ${JSON.stringify(result.want)}`); 68 } 69 ).then(() => { 70 hilog.info(DOMAIN, TAG, `open link success.`); 71 }).catch((err: BusinessError) => { 72 hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(err.code)}`); 73 }); 74 } 75 catch (e) { 76 hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(e.code)}`); 77 } 78 }) 79 } 80 .width('100%') 81 } 82 .height('100%') 83 } 84 } 85 ``` 86