• 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 { EmbeddedUIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
16import { hilog } from '@kit.PerformanceAnalysisKit';
17import { commonEventManager } from '@kit.BasicServicesKit';
18
19import { bundleManager } from '@kit.AbilityKit';
20
21const TAG: string = '[ExampleEmbeddedAbility]'
22
23export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility {
24  onCreate() {
25
26
27    console.log(TAG, `onCreate`)
28    hilog.info(0x0000, 'testTag', JSON.stringify(bundleManager.ExtensionAbilityType.EMBEDDED_UI))
29    let commonEventPublishData: commonEventManager.CommonEventPublishData = {
30      parameters: {
31        data: 'onCreate'
32      }
33    }
34    commonEventManager.publish('EmbeddedAbility_same_Instance', commonEventPublishData, async (error) => {
35      hilog.info(0x0000, 'testTag1', '%{public}s', `EmbeddedAbilityInstane publish: ${JSON.stringify(error)}`);
36    })
37  }
38
39  onForeground() {
40    console.log(TAG, `onForeground`);
41  }
42
43  onBackground() {
44    hilog.info(0x0000, 'testTag', `onBackground`)
45  }
46
47  onDestroy() {
48    console.log(TAG, `onDestroy`);
49  }
50
51  onSessionCreate(want: Want, session: UIExtensionContentSession) {
52    console.log(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`);
53    let param: Record<string, UIExtensionContentSession> = {
54      'session': session
55    };
56    let storage: LocalStorage = new LocalStorage(param);
57    session.loadContent('pages/InstancePage', storage);
58  }
59
60  onSessionDestroy(session: UIExtensionContentSession) {
61    console.log(TAG, `onSessionDestroy`);
62  }
63}