• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import { common } from '@kit.AbilityKit';
16import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions';
17import { BusinessError } from '@ohos.base';
18import hilog from '@ohos.hilog';
19
20const TAG: string = '[UIAbilityComponentsOpenLink]';
21const DOMAIN_NUMBER: number = 0xFF00;
22
23@Entry
24@Component
25struct Index {
26  build() {
27    Button('testcase4', { type: ButtonType.Capsule, stateEffect: true })
28      .width('87%')
29      .height('5%')
30      .margin({ bottom: '12vp' })
31      .onClick(() => {
32        let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
33
34        let link: string = '';
35        let link1: string = '';
36        let openLinkOptions: OpenLinkOptions = {
37          appLinkingOnly: true,
38          parameters: {demoKey: 'demo_value'}
39        };
40
41        try {
42          context.openLink(link, openLinkOptions)
43            .then(() => {
44              hilog.info(DOMAIN_NUMBER, TAG, 'open link success.');
45            }).catch((err: BusinessError) => {
46            hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
47          })
48        } catch (paramError) {
49          hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
50        }
51        try {
52          context.openLink(link1, openLinkOptions)
53            .then(() => {
54              hilog.info(DOMAIN_NUMBER, TAG, 'open link1 success.');
55            }).catch((err: BusinessError) => {
56            hilog.error(DOMAIN_NUMBER, TAG, `open link1 failed. Code is ${err.code}, message is ${err.message}`);
57          })
58        } catch (paramError) {
59          hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link1. Code is ${paramError.code}, message is ${paramError.message}`);
60        }
61      })
62
63  }
64}