• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025-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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
17import picker from '@ohos.file.picker';
18import type { BusinessError } from '@ohos.base';
19import common from '@ohos.app.ability.common';
20import commonEventManager from '@ohos.commonEventManager';
21
22let TAG = '[BT_PC_RECEIVE_PAGE]===>';
23const BT_NI_GET_URI_EVENT: string = 'ohos.event.notification.BT.GET_URI';
24
25@Entry
26@Component
27struct btCreateFilePickerPage {
28  private context = getContext(this) as common.UIAbilityContext;
29
30  aboutToAppear() {
31      console.info(TAG, `aboutToAppear`);
32      let documentSaveOptions = new picker.DocumentSaveOptions();
33      documentSaveOptions.pickerMode = picker.DocumentPickerMode.DOWNLOAD;
34      const documentPicker = new picker.DocumentViewPicker();
35      documentPicker.save(documentSaveOptions).then((documentSaveResult: Array<string>) => {
36          console.info('opp documentViewPicker.save to file succeed' + documentSaveResult.length);
37          const options: commonEventManager.CommonEventPublishData = {
38              code: 0,
39              data: 'message',
40              subscriberPermissions: [],
41              isOrdered: false,
42              isSticky: false,
43              parameters: { 'uri': documentSaveResult[0] }
44          }
45          commonEventManager.publish(BT_NI_GET_URI_EVENT, options, (err) => {
46              if (err) {
47                  console.info(TAG, `get file URI event publish failed, code is ${err.code}, message is ${err.message}`);
48              } else {
49                  console.info(TAG, `get file URI event publish success.`);
50              }
51          })
52          this.context.terminateSelf();
53      }).catch((err: BusinessError) => {
54          this.context.terminateSelf();
55          console.error(TAG, `opp Invoke documentViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
56      })
57  }
58
59  aboutToDisappear() {
60      let session = AppStorage.get<UIExtensionContentSession>('ConfirmSession');
61      if (session) {
62          console.info(TAG, `session.terminateSelf`);
63          session.terminateSelf();
64      }
65  }
66
67  onCancel() {
68      console.info(TAG, `onCancel is called`)
69  }
70
71  build() {
72  }
73}