1e41f4b71Sopenharmony_ci# @ohos.app.ability.OpenLinkOptions (OpenLinkOptions)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciOpenLinkOptions可以作为[openLink()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextopenlink12)的入参,用于标识是否仅打开AppLinking和传递键值对可选参数。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> - 本模块接口仅可在Stage模型下使用。
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { OpenLinkOptions } from '@kit.AbilityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## 属性
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 |
24e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
25e41f4b71Sopenharmony_ci| appLinkingOnly | boolean | 否 | 是 | 表示是否必须以AppLinking的方式启动UIAbility。<br />- 取值为true时,如果不存在与AppLinking相匹配的UIAbility,直接返回。<br />- 取值为false时,如果不存在与AppLinking相匹配的UIAbility,AppLinking会退化为DeepLink。默认值为false。<br />aa命令隐式拉起Ability时可以通过设置"--pb appLinkingOnly true/false"以AppLinking的方式进行启动。 |
26e41f4b71Sopenharmony_ci| parameters | Record\<string, Object> | 否 | 是 | 表示WantParams参数。 |
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**示例:**
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci  ```ts
31e41f4b71Sopenharmony_ci  import { common, OpenLinkOptions } from '@kit.AbilityKit';
32e41f4b71Sopenharmony_ci  import { hilog } from '@kit.PerformanceAnalysisKit';
33e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci  const DOMAIN = 0xeeee;
36e41f4b71Sopenharmony_ci  const TAG: string = '[openLinkDemo]';
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci  @Entry
39e41f4b71Sopenharmony_ci  @Component
40e41f4b71Sopenharmony_ci  struct Index {
41e41f4b71Sopenharmony_ci    @State message: string = 'I am caller';
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci    build() {
44e41f4b71Sopenharmony_ci      Row() {
45e41f4b71Sopenharmony_ci        Column() {
46e41f4b71Sopenharmony_ci          Text(this.message)
47e41f4b71Sopenharmony_ci            .fontSize(50)
48e41f4b71Sopenharmony_ci            .fontWeight(FontWeight.Bold)
49e41f4b71Sopenharmony_ci          Button('start browser', { type: ButtonType.Capsule, stateEffect: true })
50e41f4b71Sopenharmony_ci            .width('87%')
51e41f4b71Sopenharmony_ci            .height('5%')
52e41f4b71Sopenharmony_ci            .margin({ bottom: '12vp' })
53e41f4b71Sopenharmony_ci            .onClick(() => {
54e41f4b71Sopenharmony_ci              let context = getContext(this) as common.UIAbilityContext;
55e41f4b71Sopenharmony_ci              let link: string = 'https://www.example.com';
56e41f4b71Sopenharmony_ci              let openLinkOptions: OpenLinkOptions = {
57e41f4b71Sopenharmony_ci                appLinkingOnly: true,
58e41f4b71Sopenharmony_ci                parameters: { demo_key: 'demo_value' }
59e41f4b71Sopenharmony_ci              };
60e41f4b71Sopenharmony_ci              try {
61e41f4b71Sopenharmony_ci                context.openLink(
62e41f4b71Sopenharmony_ci                  link,
63e41f4b71Sopenharmony_ci                  openLinkOptions,
64e41f4b71Sopenharmony_ci                  (err, result) => {
65e41f4b71Sopenharmony_ci                    hilog.error(DOMAIN, TAG, `openLink callback error.code: ${JSON.stringify(err)}`);
66e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN, TAG, `openLink callback result: ${JSON.stringify(result.resultCode)}`);
67e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN, TAG, `openLink callback result data: ${JSON.stringify(result.want)}`);
68e41f4b71Sopenharmony_ci                  }
69e41f4b71Sopenharmony_ci                ).then(() => {
70e41f4b71Sopenharmony_ci                  hilog.info(DOMAIN, TAG, `open link success.`);
71e41f4b71Sopenharmony_ci                }).catch((err: BusinessError) => {
72e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(err.code)}`);
73e41f4b71Sopenharmony_ci                });
74e41f4b71Sopenharmony_ci              }
75e41f4b71Sopenharmony_ci              catch (e) {
76e41f4b71Sopenharmony_ci                hilog.error(DOMAIN, TAG, `open link failed, errCode: ${JSON.stringify(e.code)}`);
77e41f4b71Sopenharmony_ci              }
78e41f4b71Sopenharmony_ci            })
79e41f4b71Sopenharmony_ci        }
80e41f4b71Sopenharmony_ci        .width('100%')
81e41f4b71Sopenharmony_ci      }
82e41f4b71Sopenharmony_ci      .height('100%')
83e41f4b71Sopenharmony_ci    }
84e41f4b71Sopenharmony_ci  }
85e41f4b71Sopenharmony_ci  ```
86