• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15
16import type common from '@ohos.app.ability.common';
17import particleAbility from '@ohos.ability.particleAbility';
18import type Want from '@ohos.app.ability.Want';
19import type { BusinessError } from '@ohos.base';
20import hilog from '@ohos.hilog';
21
22const TAG: string = '[Sample_FAModelAbilityDevelop]';
23const domain: number = 0xFF00;
24
25class ServiceAbilityStartUiAbility {
26  onStart(): void {
27    // 启动UIAbility
28    let want: Want = {
29      bundleName: 'ohos.samples.etsclock',
30      abilityName: 'MainAbility'
31    };
32    particleAbility.startAbility({ want }).then(() => {
33      hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Start Ability successfully.');
34    }).catch((error: BusinessError) => {
35      hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Ability failed: ' + JSON.stringify(error));
36    });
37
38    // 访问ServiceExtensionAbility
39    let serviceWant: Want = {
40      bundleName: 'com.samples.stagemodelabilityinteraction',
41      abilityName: 'ServiceExtAbility'
42    };
43    let faConnect: common.ConnectOptions = {
44      onConnect: (elementName, proxy) => {
45        hilog.info(domain, TAG, 'FaConnection onConnect called.');
46      },
47      onDisconnect: (elementName) => {
48        hilog.info(domain, TAG, 'FaConnection onDisconnect called.');
49      },
50      onFailed: (code) => {
51        hilog.info(domain, TAG, 'FaConnection onFailed code is: ' + code);
52      }
53    };
54    let connectionId = particleAbility.connectAbility(serviceWant, faConnect);
55    hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility ServiceAbility onStart');
56  }
57};
58
59export default new ServiceAbilityStartUiAbility();