1# @ohos.app.ability.OpenLinkOptions (OpenLinkOptions)
2
3OpenLinkOptions可以作为[openLink()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12)的入参,用于标识是否仅打开AppLinking和传递键值对可选参数。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> - 本模块接口仅可在Stage模型下使用。
10
11## 导入模块
12
13```ts
14import { OpenLinkOptions } from '@kit.AbilityKit';
15```
16
17## 属性
18
19**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。
20
21**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
22
23| 名称 | 类型 | 只读 | 可选 | 说明 |
24| -------- | -------- | -------- | -------- | -------- |
25| appLinkingOnly | boolean | 否 | 是 | 表示是否必须以AppLinking的方式启动UIAbility。<br />- 取值为true时,如果不存在与AppLinking相匹配的UIAbility,直接返回。<br />- 取值为false时,如果不存在与AppLinking相匹配的UIAbility,AppLinking会退化为DeepLink。默认值为false。<br />aa命令隐式拉起Ability时可以通过设置"--pb appLinkingOnly true/false"以AppLinking的方式进行启动。 |
26| parameters | Record\<string, Object> | 否 | 是 | 表示WantParams参数。<br/>**说明**:具体使用规则请参考[want](./js-apis-app-ability-want.md)中的parameters属性。 |
27
28**示例:**
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