• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 UIAbility from '@ohos.app.ability.UIAbility'
16import logger from '../Model/Logger'
17import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
18import type { Permissions } from '@ohos.abilityAccessCtrl'
19
20const TAG: string = 'MainAbility'
21
22export default class MainAbility extends UIAbility {
23  async onCreate(want, launchParam) {
24    logger.info(TAG, `[Demo] MainAbility onCreate`)
25
26    const PERMISSIONS: Array<Permissions> = [
27      'ohos.permission.USE_BLUETOOTH',
28      'ohos.permission.DISCOVER_BLUETOOTH',
29      'ohos.permission.LOCATION',
30      'ohos.permission.MANAGE_BLUETOOTH',
31      'ohos.permission.APPROXIMATELY_LOCATION'
32    ]
33
34    let atManager = abilityAccessCtrl.createAtManager()
35    try {
36      atManager.requestPermissionsFromUser(this.context, PERMISSIONS).then((data) => {
37        logger.info(TAG, `data: ${JSON.stringify(data)}`)
38      }).catch((err) => {
39        logger.info(TAG, `err: ${JSON.stringify(err)}`)
40      })
41    } catch (err) {
42      logger.info(TAG, `catch err->${JSON.stringify(err)}`);
43    }
44  }
45
46  onDestroy() {
47    logger.info(TAG, `[Demo] MainAbility onDestroy`)
48  }
49
50  onWindowStageCreate(windowStage) {
51    logger.info(TAG, `[Demo] MainAbility onWindowStageCreate`)
52    windowStage.setUIContent(this.context, "pages/Index", null)
53  }
54
55  onWindowStageDestroy() {
56    logger.info(TAG, `[Demo] MainAbility onWindowStageDestroy`)
57  }
58
59  onForeground() {
60    logger.info(TAG, `[Demo] MainAbility onForeground`)
61  }
62
63  onBackground() {
64    logger.info(TAG, `[Demo] MainAbility onBackground`)
65  }
66}
67