• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
17import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
18import Want from '@ohos.app.ability.Want';
19import type { BusinessError } from '@ohos.base';
20
21const TAG: string = '[BT_RECEIVE_UI]==>'
22
23export default class BluetoothReceiveServiceUIAbility extends UIExtensionAbility {
24    onSessionCreate(want: Want, session: UIExtensionContentSession) {
25        if (want.parameters == undefined) {
26            return;
27        }
28
29        let fileUri = want.parameters?.['fileUri'];
30        if (fileUri != undefined && fileUri != '') {
31            console.info(TAG, 'pullUpFileManager invoked.');
32            let want: Want = {
33                bundleName: 'com.huawei.hmos.files',
34                abilityName: 'EntryAbility',
35                parameters: {
36                    'fileUri': fileUri
37                }
38            };
39            this.context.startAbility(want)
40            .then(() => {
41                console.info(TAG, 'pullUpFileManager successfully and terminateSelf');
42                this.context.terminateSelf();
43            })
44            .catch((err: BusinessError) => {
45                console.warn(TAG, 'pullUpFileManager failed');
46                want.bundleName = 'com.huawei.hmos.filemanager';
47                want.abilityName = 'MainAbility';
48                this.context.startAbility(want);
49            });
50            console.info(TAG, 'pullUpFileManager end.');
51            return;
52        }
53
54        let param: Record<string, UIExtensionContentSession> = {
55            'session': session
56        }
57        let storage: LocalStorage = new LocalStorage(param);
58        session.loadContent('pages/BluetoothReceive', storage);
59        session.setWindowBackgroundColor('#00000000');
60        AppStorage.setOrCreate('ConfirmSession', session);
61    }
62
63    onSessionDestroy(session: UIExtensionContentSession) {
64        console.info(TAG, 'BluetoothReceiveServiceUIAbility onSessionDestroy');
65    }
66}