1/* 2 * Copyright (c) 2022 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 prompt from '@ohos.prompt' 17import Logger from '../util/Logger' 18 19const TAG: string = 'FormExtContextController' 20 21let want = { 22 moduleName: 'entry', 23 bundleName: 'ohos.samples.stagemodel', 24 abilityName: 'FormAbility', 25} 26 27export default class FormExtContextController { 28 private regOnRelease(caller) { 29 try { 30 caller.onRelease((msg) => { 31 Logger.info(TAG, `caller onRelease is called ${msg}`) 32 }) 33 Logger.info(TAG, 'caller register OnRelease succeed') 34 } catch (error) { 35 Logger.error(TAG, `caller register OnRelease failed with ${error}`) 36 } 37 } 38 39 // 拉起一个卡片所属应用的Ability。 40 startAbility(context) { 41 context.startAbility(want).then(() => { 42 Logger.info(TAG, `StartAbility Success`) 43 prompt.showToast({ 44 message: 'FormExtensionContext success' 45 }) 46 }).catch((error) => { 47 Logger.error(TAG, `StartAbility failed: ${error}`) 48 prompt.showToast({ 49 message: `StartAbility failed: ${error}` 50 }) 51 }) 52 } 53}