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.<br>**NOTE**: For details about the usage rules, see **parameters** in [want](./js-apis-app-ability-want.md).| 27 28**Example** 29 30 ```ts 31 import { common, OpenLinkOptions, wantConstant } 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: { 59 [wantConstant.Params.CONTENT_TITLE_KEY]: 'contentTitle', 60 keyString: 'str', 61 keyNumber: 200, 62 keyBool: false, 63 keyObj: { 64 keyObjKey: 'objValue', 65 } 66 } 67 }; 68 try { 69 context.openLink( 70 link, 71 openLinkOptions, 72 (err, result) => { 73 hilog.error(DOMAIN, TAG, `openLink callback error.code: ${JSON.stringify(err)}`); 74 hilog.info(DOMAIN, TAG, `openLink callback result: ${JSON.stringify(result.resultCode)}`); 75 hilog.info(DOMAIN, TAG, `openLink callback result data: ${JSON.stringify(result.want)}`); 76 } 77 ).then(() => { 78 hilog.info(DOMAIN, TAG, `open link success.`); 79 }).catch((err: BusinessError) => { 80 hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(err.code)}`); 81 }); 82 } 83 catch (e) { 84 hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(e.code)}`); 85 } 86 }) 87 } 88 .width('100%') 89 } 90 .height('100%') 91 } 92 } 93 ``` 94