1/* 2 * Copyright (c) 2021-2024 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 UIAbility from '@ohos.app.ability.UIAbility'; 17import hilog from '@ohos.hilog'; 18import window from '@ohos.window'; 19import AcCtrl from '@ohos.abilityAccessCtrl'; 20 21let AcManager = AcCtrl.createAtManager(); 22export default class MainAbility extends UIAbility { 23 onCreate(want, launchParam) { 24 console.info('AceApplication onCreate'); 25 26 console.info('Calc[IndexPage] grantPermission'); 27 AcManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], function (result) { 28 console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser'); 29 }); 30 } 31 32 onDestroy() { 33 console.info("onDestroy"); 34 } 35 36 onWindowStageCreate(windowStage: window.WindowStage) { 37 // Main window is created, set main page for this ability 38 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 39 40 windowStage.loadContent('pages/Index', (err, data) => { 41 if (err.code) { 42 hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 43 return; 44 } 45 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 46 }); 47 } 48 49 onWindowStageDestroy() { 50 // Main window is destroyed, release UI related resources 51 console.info("onWindowStageDestroy"); 52 } 53 54 onForeground() { 55 // Ability has brought to foreground 56 console.info("onForeground"); 57 } 58 59 onBackground() { 60 // Ability has back to background 61 console.info("onBackground"); 62 } 63 64}; 65