DEV Community

Cover image for Responding to Back Events, Screen Rotation, Checking Screen Recording, Actively Opening Interfaces, Screen Brightness Issues
kouwei qing
kouwei qing

Posted on

Responding to Back Events, Screen Rotation, Checking Screen Recording, Actively Opening Interfaces, Screen Brightness Issues

[Daily HarmonyOS Next Knowledge] Responding to Back Events, Screen Rotation, Checking Screen Recording, Actively Opening Interfaces, Screen Brightness Issues

1. How to create a Window in HarmonyOS that can respond to back events and allow click events to penetrate?

I want to create a custom View to display Toast or pop-ups above all pages. When showing a Toast, all operations should pass through the Toast's page. Currently, using a custom Window to load the page, but events in the Window-created page cannot penetrate, and click events are unresponsive.

Solution: Use sub_windowClass.setWindowTouchable(false).

Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#ZH-CN_TOPIC_0000001884757714__setwindowtouchable9

2. When using setPreferredOrientation for screen rotation in HarmonyOS, the interface returns success before the screen rotates (even the status bar hasn't adjusted yet)?

setPreferredOrientation calls the callback before rotation completes. This interface only issues a rotation command and callbacks immediately after issuance.

Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setpreferredorientation9

Explanation: Screen rotation involves an animation with variable duration. The success callback is issued once the command is sent, not after the animation finishes. Rotation animations can be interrupted: if a new rotation command is received before the previous animation ends, the prior animation is canceled.

3. How to detect screen recording or screen sharing on HarmonyOS devices?

Can we detect if the built-in screen recording function is active or if the device is sharing its screen (e.g., in enterprise meetings)?

Solution: Monitor changes in screen capture, casting, and recording status.

Reference: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-display-V5#ZH-CN_TOPIC_0000001930756769__displayoncapturestatuschange12

4. How to actively open an interface/dialog via an API in HarmonyOS?

Currently, the new interface syntax is unsupported. Instead, use implementation classes or @State-typed variables, with specific display and interaction logic handled by the caller through class implementation.

Reference demo:

export interface Month {
  month: string; // Specific year and month
  num: number;   // Month number
  days: number[]; // Dates of the month
  lunarDays: string[]; // Lunar dates
  year: number;  // Year
}

class myMonth implements Month {
  month: string = '';
  num: number = 0;
  days: number[] = [111];
  lunarDays: string[] = ['1'];
  year: number = 1;
}

@AppRouter({ name: "highlyloadedcomponentrender/MainPage" })
@Component
export struct MainPage {
  @State mymount: Month = {
    month: '',
    num: 0,
    days: [],
    lunarDays: [],
    year: 0
  };
  private month = new myMonth();
  // ...
}
Enter fullscreen mode Exit fullscreen mode

5. Inconsistent brightness causes poor experience in HarmonyOS?

After setting the brightness within an app window, returning to the home screen restores the system brightness. If the app's brightness differs significantly from the system's, the sudden change is noticeable.

Solutions:

Top comments (0)