1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import AbilityConstant from '@ohos.app.ability.AbilityConstant';
- import hilog from '@ohos.hilog';
- import UIAbility from '@ohos.app.ability.UIAbility';
- import Want from '@ohos.app.ability.Want';
- import window from '@ohos.window';
- import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
- import { GlobalContext } from '../utils/GlobalThis';
- export default class EntryAbility extends UIAbility {
- onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
- GlobalContext.getContext().setObject("context", this.context);
- GlobalContext.getContext().setObject("pathDir", this.context.filesDir);
- }
- onDestroy(): void {
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
- }
- onWindowStageCreate(windowStage: window.WindowStage): void {
- let AtManager = abilityAccessCtrl.createAtManager();
- AtManager.requestPermissionsFromUser(this.context, ['ohos.permission.READ_MEDIA', 'ohos.permission.WRITE_MEDIA',
- 'ohos.permission.CAMERA', 'ohos.permission.MICROPHONE', 'ohos.permission.START_INVISIBLE_ABILITY']).then(() => {
- });
- // Main window is created, set main page for this ability
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
- // 1.获取应用主窗口。
- let windowClass: window.Window
- windowStage.getMainWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
- // 2.实现沉浸式效果:设置导航栏、状态栏不显示。
- let names: [] = [];
- windowClass.setWindowSystemBarEnable(names, (err) => {
- if (err.code) {
- console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the system bar to be visible.');
- });
- windowClass.setWindowLayoutFullScreen(true)
- })
- // ================================= 更改跟路由
- windowStage.loadContent('pages/TestHdcInstallPage', (err) => {
- if (err.code) {
- hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
- return;
- }
- hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
- });
- }
- onWindowStageDestroy(): void {
- // Main window is destroyed, release UI related resources
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
- }
- onForeground(): void {
- // Ability has brought to foreground
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
- }
- onBackground(): void {
- // Ability has back to background
- hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
- }
- }
|