• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.OpenLinkOptions (Optional Parameters of openLink)
2
3<!--Kit: Ability Kit-->
4<!--Subsystem: Ability-->
5<!--Owner: @hanchen45; @Luobniz21-->
6<!--Designer: @ccllee1-->
7<!--Tester: @lixueqing513-->
8<!--Adviser: @huipeizi-->
9
10**OpenLinkOptions** can be used as an input parameter of [openLink()](js-apis-inner-application-uiAbilityContext.md#openlink12) to indicate whether to enable only App Linking and pass in optional parameters in the form of key-value pairs.
11
12> **NOTE**
13>
14> - 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.
15>
16> - The APIs of this module can be used only in the stage model.
17
18## Modules to Import
19
20```ts
21import { OpenLinkOptions } from '@kit.AbilityKit';
22```
23
24## OpenLinkOptions
25
26**Atomic service API**: This API can be used in atomic services since API version 12.
27
28**System capability**: SystemCapability.Ability.AbilityRuntime.Core
29
30| Name| Type| Read Only| Optional| Description|
31| -------- | -------- | -------- | -------- | -------- |
32| appLinkingOnly | boolean | No| Yes| Whether the UIAbility must be started using <!--RP1-->[App Linking](../../application-models/app-linking-startup.md)<!--RP1End-->.<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 falls back to [Deep Linking](../../application-models/deep-linking-startup.md). 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.|
33| 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).|
34
35**Example**
36
37  ```ts
38  import { common, OpenLinkOptions, wantConstant } from '@kit.AbilityKit';
39  import { hilog } from '@kit.PerformanceAnalysisKit';
40  import { BusinessError } from '@kit.BasicServicesKit';
41
42  const DOMAIN = 0xeeee;
43  const TAG: string = '[openLinkDemo]';
44
45  @Entry
46  @Component
47  struct Index {
48    @State message: string = 'I am caller';
49
50    build() {
51      Row() {
52        Column() {
53          Text(this.message)
54            .fontSize(50)
55            .fontWeight(FontWeight.Bold)
56          Button('start browser', { type: ButtonType.Capsule, stateEffect: true })
57            .width('87%')
58            .height('5%')
59            .margin({ bottom: '12vp' })
60            .onClick(() => {
61              let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
62              let link: string = 'https://www.example.com';
63              let openLinkOptions: OpenLinkOptions = {
64                appLinkingOnly: true,
65                parameters: {
66                  [wantConstant.Params.CONTENT_TITLE_KEY]: 'contentTitle',
67                  keyString: 'str',
68                  keyNumber: 200,
69                  keyBool: false,
70                  keyObj: {
71                    keyObjKey: 'objValue',
72                  }
73                }
74              };
75              try {
76                context.openLink(
77                  link,
78                  openLinkOptions,
79                  (err, result) => {
80                    hilog.error(DOMAIN, TAG, `openLink callback error.code: ${JSON.stringify(err)}`);
81                    hilog.info(DOMAIN, TAG, `openLink callback result: ${JSON.stringify(result.resultCode)}`);
82                    hilog.info(DOMAIN, TAG, `openLink callback result data: ${JSON.stringify(result.want)}`);
83                  }
84                ).then(() => {
85                  hilog.info(DOMAIN, TAG, `open link success.`);
86                }).catch((err: BusinessError) => {
87                  hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(err.code)}`);
88                });
89              }
90              catch (e) {
91                hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(e.code)}`);
92              }
93            })
94        }
95        .width('100%')
96      }
97      .height('100%')
98    }
99  }
100  ```
101