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参数。 |
27
28**示例:**
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