• 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, StartOptions, UIExtensionContentSession, Want } from '@kit.AbilityKit';
16import { hilog } from '@kit.PerformanceAnalysisKit';
17import { BusinessError } from '@kit.BasicServicesKit';
18
19const TAG: string = '[ExampleEmbeddedAbility]'
20
21export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility {
22  onCreate() {
23    console.log(TAG, `onCreate`)
24    let want: Want = {
25      deviceId: '',
26      bundleName: 'com.example.act_embeddeduiextension',
27      abilityName: 'EntryAbilityd',
28    }
29    let options: StartOptions = {
30      displayId: 0
31    };
32    try {
33      this.context.startAbility(want, options).then(() => {
34        hilog.info(0x0000, TAG, '%{public}s',
35          `start ability successful,result123: `);
36        hilog.info(0x0000, TAG, 'succeed');
37      }).catch((err: BusinessError) => {
38        hilog.info(0x0000, TAG, '%{public}s', `start ablility err : ${err}`);
39      })
40    } catch (error) {
41      hilog.info(0x0000, TAG, '%{public}s', `start fail : ${error}`);
42    }
43  }
44
45  onForeground() {
46    console.log(TAG, `onForeground`);
47  }
48
49  onBackground() {
50    hilog.info(0x0000, 'testTag', `onBackground`)
51  }
52
53  onDestroy() {
54    console.log(TAG, `onDestroy`);
55  }
56
57  onSessionCreate(want: Want, session: UIExtensionContentSession) {
58    console.log(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`);
59    let param: Record<string, UIExtensionContentSession> = {
60      'session': session
61    };
62    let storage: LocalStorage = new LocalStorage(param);
63    session.loadContent('pages/Index', storage);
64  }
65
66  onSessionDestroy(session: UIExtensionContentSession) {
67    console.log(TAG, `onSessionDestroy`);
68  }
69}