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 console.log(TAG, `onCreate`) 26 hilog.info(0x0000, 'testTag', JSON.stringify(bundleManager.ExtensionAbilityType.EMBEDDED_UI)) 27 28 } 29 30 onForeground() { 31 console.log(TAG, `onForeground`); 32 } 33 34 onBackground() { 35 hilog.info(0x0000, 'testTag', `onBackground`) 36 let commonEventPublishData: commonEventManager.CommonEventPublishData = { 37 parameters: { 38 data: '111' 39 } 40 } 41 commonEventManager.publish('AbilityOnBackgroundA', commonEventPublishData, async (error) => { 42 hilog.info(0x0000, 'testTag1', '%{public}s', `onForeground publish: ${JSON.stringify(error)}`); 43 }) 44 } 45 46 onDestroy() { 47 console.log(TAG, `onDestroy`); 48 } 49 50 onSessionCreate(want: Want, session: UIExtensionContentSession) { 51 console.log(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`); 52 let param: Record<string, UIExtensionContentSession> = { 53 'session': session 54 }; 55 let storage: LocalStorage = new LocalStorage(param); 56 session.loadContent('pages/extension', storage); 57 } 58 59 onSessionDestroy(session: UIExtensionContentSession) { 60 console.log(TAG, `onSessionDestroy`); 61 } 62}