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 */ 15import rpc from '@ohos.rpc'; 16import hilog from '@ohos.hilog'; 17import promptAction from '@ohos.promptAction'; 18import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 19import type Want from '@ohos.application.Want'; 20import GlobalContext from './GlobalParam'; 21 22const TAG = 'ToastExtensionAbility'; 23const INFO = '读取了剪贴板信息'; 24 25class ToastStub extends rpc.RemoteObject { 26 constructor(des: string) { 27 super(des); 28 } 29} 30 31export default class ToastExtensionAbility extends ServiceExtensionAbility { 32 onCreate(want: Want): void { 33 hilog.info(0, TAG, 'onCreate'); 34 GlobalContext.getInstance().context = this.context; 35 } 36 37 onConnect(want: Want): ToastStub { 38 hilog.info(0, TAG, 'onConnect'); 39 let showInfo: string = want.parameters.appName + INFO; 40 promptAction.showToast({message:showInfo}); 41 return new ToastStub('PasteboardToast'); 42 } 43 44 onRequest(want: Want, startId: number): void { 45 hilog.info(0, TAG, 'onRequest'); 46 this.onConnect(want); 47 } 48 49 onDisconnet(): void { 50 hilog.info(0, TAG, 'onDisconnet'); 51 this.onDestroy(); 52 } 53 54 onDestroy(): void { 55 hilog.info(0, TAG, 'onDestroy'); 56 GlobalContext.getInstance().context.terminateSelf(); 57 } 58} 59