EntryAbility.ets 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import AbilityConstant from '@ohos.app.ability.AbilityConstant';
  2. import hilog from '@ohos.hilog';
  3. import UIAbility from '@ohos.app.ability.UIAbility';
  4. import Want from '@ohos.app.ability.Want';
  5. import window from '@ohos.window';
  6. export default class EntryAbility extends UIAbility {
  7. onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  8. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
  9. }
  10. onDestroy(): void {
  11. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  12. }
  13. onWindowStageCreate(windowStage: window.WindowStage): void {
  14. // Main window is created, set main page for this ability
  15. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
  16. // 1.获取应用主窗口。
  17. let windowClass: window.Window
  18. windowStage.getMainWindow((err, data) => {
  19. if (err.code) {
  20. console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
  21. return;
  22. }
  23. windowClass = data;
  24. console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
  25. // 2.实现沉浸式效果:设置导航栏、状态栏不显示。
  26. let names: [] = [];
  27. windowClass.setWindowSystemBarEnable(names, (err) => {
  28. if (err.code) {
  29. console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
  30. return;
  31. }
  32. console.info('Succeeded in setting the system bar to be visible.');
  33. });
  34. windowClass.setWindowLayoutFullScreen(true)
  35. })
  36. windowStage.loadContent('pages/WorkshopPage', (err) => {
  37. if (err.code) {
  38. hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
  39. return;
  40. }
  41. hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
  42. });
  43. }
  44. onWindowStageDestroy(): void {
  45. // Main window is destroyed, release UI related resources
  46. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  47. }
  48. onForeground(): void {
  49. // Ability has brought to foreground
  50. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
  51. }
  52. onBackground(): void {
  53. // Ability has back to background
  54. hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
  55. }
  56. }