1/* 2 * Copyright (C) 2023-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 '@kit.AbilityKit'; 17import { window } from '@kit.ArkUI'; 18import { abilityAccessCtrl } from '@kit.AbilityKit'; 19import { Permissions } from '@kit.AbilityKit'; 20import Logger from '../utils/Logger'; 21import { BusinessError } from '@ohos.base'; 22 23/** 24 * Lift cycle management of Ability. 25 */ 26export default class EntryAbility extends UIAbility { 27 onCreate(want, launchParam) { 28 Logger.info('Sample_VideoRecorder', 'Ability onCreate,requestPermissionsFromUser'); 29 let permissionNames: Array<Permissions> = ['ohos.permission.MEDIA_LOCATION', 'ohos.permission.READ_MEDIA', 30 'ohos.permission.WRITE_MEDIA', 'ohos.permission.CAMERA', 'ohos.permission.MICROPHONE', 31 'ohos.permission.DISTRIBUTED_DATASYNC']; 32 abilityAccessCtrl.createAtManager().requestPermissionsFromUser(this.context, permissionNames).then((data) => { 33 console.log("Sample_VideoRecorder", data); 34 }).catch((err: BusinessError) => { 35 console.log("Sample_VideoRecorder", err.message); 36 }); 37 } 38 39 onDestroy() { 40 Logger.info('Sample_VideoRecorder', 'Ability onDestroy'); 41 } 42 43 async onWindowStageCreate(windowStage: window.WindowStage) { 44 // Main window is created, set main page for this ability 45 Logger.info('Sample_VideoRecorder', 'Ability onWindowStageCreate'); 46 47 windowStage.loadContent('pages/ListPage', (err, data) => { 48 if (err.code) { 49 Logger.error('Sample_VideoRecorder', 'Failed to load the content. Cause: ' + JSON.stringify(err)); 50 return; 51 } 52 Logger.info('Sample_VideoRecorder', 'Succeeded in loading the content. Data: ' + JSON.stringify(data)); 53 windowStage.getMainWindow().then((win: window.Window) => { 54 win.setKeepScreenOn(true); 55 }) 56 }); 57 } 58 59 onWindowStageDestroy() { 60 // Main window is destroyed, release UI related resources 61 Logger.info('Sample_VideoRecorder', 'Ability onWindowStageDestroy'); 62 } 63 64 onForeground() { 65 // Ability has brought to foreground 66 Logger.info('Sample_VideoRecorder', 'Ability onForeground'); 67 } 68 69 onBackground() { 70 // Ability has back to background 71 Logger.info('Sample_VideoRecorder', 'Ability onBackground'); 72 } 73}