openharmony 鸿蒙 js-apis-display

2025-06-12 浏览 (1)

@ohos.display (Display)

The Display module provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays.

NOTE

The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { display } from '@kit.ArkUI';

DisplayState

Enumerates the states of a display.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameValueDescription
STATE_UNKNOWN0Unknown.
STATE_OFF1The display is shut down.
STATE_ON2The display is powered on.
STATE_DOZE3The display is in sleep mode.
STATE_DOZE_SUSPEND4The display is in sleep mode, and the CPU is suspended.
STATE_VR5The display is in VR mode.
STATE_ON_SUSPEND6The display is powered on, and the CPU is suspended.

Orientation10+

Enumerates the orientations of a display.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameValueDescription
PORTRAIT0The display is in portrait mode.
LANDSCAPE1The display is in landscape mode.
PORTRAIT_INVERTED2The display is in reverse portrait mode.
LANDSCAPE_INVERTED3The display is in reverse landscape mode.

DisplaySourceMode19+

Enumerates the display modes for screen content.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.Window.SessionManager

NameValueDescription
NONE0The device is currently not in use.
MAIN1The primary screen of the device is currently in use.
MIRROR2The device is currently in mirror display mode.
EXTEND3The device is currently in extended display mode.
ALONE4The device is currently in independent display mode.

FoldStatus10+

Enumerates the fold statuses of a foldable device. For dual-fold axis devices, when oriented with the charging port at the bottom, the hinges are identified from right to left as the first and second fold axes, respectively.

System capability: SystemCapability.Window.SessionManager

NameValueDescription
FOLD_STATUS_UNKNOWN10+0The fold status of the device is unknown.
Atomic service API: This API can be used in atomic services since API version 12.
FOLD_STATUS_EXPANDED10+1The device is fully open. For dual-fold axis devices, the first fold axis is fully open, and the second fold axis is folded.
Atomic service API: This API can be used in atomic services since API version 12.
FOLD_STATUS_FOLDED10+2The device is folded (completely closed). For dual-fold axis devices, the first fold axis is folded, and the second fold axis is folded.
Atomic service API: This API can be used in atomic services since API version 12.
FOLD_STATUS_HALF_FOLDED10+3The device is half-folded, somehow between fully open and completely closed. For dual-fold axis devices, the first fold axis is half-folded, and the second fold axis is folded.
Atomic service API: This API can be used in atomic services since API version 12.
FOLD_STATUS_EXPANDED_WITH_SECOND_EXPANDED15+11For dual-fold axis devices, the first fold axis is fully open, and the second fold axis is fully open.
Atomic service API: This API can be used in atomic services since API version 15.
FOLD_STATUS_EXPANDED_WITH_SECOND_HALF_FOLDED15+21For dual-fold axis devices, the first fold axis is fully open, and the second fold axis is half-folded.
Atomic service API: This API can be used in atomic services since API version 15.
FOLD_STATUS_FOLDED_WITH_SECOND_EXPANDED15+12For dual-fold axis devices, the first fold axis is folded, and the second fold axis is fully open.
Atomic service API: This API can be used in atomic services since API version 15.
FOLD_STATUS_FOLDED_WITH_SECOND_HALF_FOLDED15+22For dual-fold axis devices, the first fold axis is folded, and the second fold axis is fully folded.
Atomic service API: This API can be used in atomic services since API version 15.
FOLD_STATUS_HALF_FOLDED_WITH_SECOND_EXPANDED15+13For dual-fold axis devices, the first fold axis is half-folded, and the second fold axis is fully open.
Atomic service API: This API can be used in atomic services since API version 15.
FOLD_STATUS_HALF_FOLDED_WITH_SECOND_HALF_FOLDED15+23For dual-fold axis devices, the first fold axis is half-folded, and the second fold axis is half-folded.
Atomic service API: This API can be used in atomic services since API version 15.

NOTE

Devices with only one fold axis can be in the FOLD_STATUS_EXPANDED, FOLD_STATUS_FOLDED, or FOLD_STATUS_HALF_FOLDED state.

Devices with two fold axes can be in any of the states provided in the table above, except for FOLD_STATUS_UNKNOWN, which indicates an unusable fold status.

FoldDisplayMode10+

Enumerates the display modes of a foldable device.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

NameValueDescription
FOLD_DISPLAY_MODE_UNKNOWN0The display mode of the device is unknown.
FOLD_DISPLAY_MODE_FULL1The device is displayed in full screen.
FOLD_DISPLAY_MODE_MAIN2The primary screen of the device is displayed.
FOLD_DISPLAY_MODE_SUB3The secondary screen of the device is displayed.
FOLD_DISPLAY_MODE_COORDINATION4Both screens of the device are displayed in collaborative mode.

NOTE For foldable devices where both the inner and outer screens can serve as the primary screen, the inner screen's display mode is FOLD_DISPLAY_MODE_FULL, and the outer screen's display mode is FOLD_DISPLAY_MODE_MAIN.

For foldable devices where the outer screen serves only as an auxiliary display, the inner screen's display mode is FOLD_DISPLAY_MODE_MAIN, and the outer screen's display mode is FOLD_DISPLAY_MODE_SUB.

FoldCreaseRegion10+

Defines the crease region of a foldable device.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

NameTypeReadableWritableDescription
displayIdnumberYesNoID of the display where the crease is located.
creaseRectsArray<Rect>YesNoCrease region.

Rect9+

Describes a rectangle on the display.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeReadableWritableDescription
leftnumberYesYesLeft boundary of the rectangle, in px. The value is an integer.
topnumberYesYesTop boundary of the rectangle, in px. The value is an integer.
widthnumberYesYesWidth of the rectangle, in px. The value is an integer.
heightnumberYesYesHeight of the rectangle, in px. The value is an integer.

WaterfallDisplayAreaRects9+

Describes the curved area on a waterfall display.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeReadableWritableDescription
leftRectYesNoRectangle of the curved area on the left of the waterfall display.
topRectYesNoRectangle of the curved area on the top of the waterfall display.
rightRectYesNoRectangle of the curved area on the right of the waterfall display.
bottomRectYesNoRectangle of the curved area at the bottom of the waterfall display.

CutoutInfo9+

Describes the unusable area of a display, including punch hole, notch, and curved area of a waterfall display.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeReadableWritableDescription
boundingRectsArray<Rect>YesNoUnusable areas (bounding rectangles) designed for punch holes and notches. If there are no punch holes or notches, an empty array is returned.
waterfallDisplayAreaRectsWaterfallDisplayAreaRectsYesNoCurved area on a waterfall display.

DisplayPhysicalResolution12+

Describes the display mode of a foldable device and the corresponding physical screen resolution information.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeRead-OnlyOptionalDescription
foldDisplayModeFoldDisplayModeYesNoDisplay mode of the foldable device.
physicalWidthnumberYesNoWidth of the foldable device, in px. The value is an integer greater than 0.
physicalHeightnumberYesNoHeight of the foldable device, in px. The value is an integer greater than 0.

ScreenShape18+

Enumerates the screen shapes of a display.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameValueDescription
RECTANGLE0The screen is in the shape of a rectangle.
ROUND1The screen is in the shape of a circle.

VirtualScreenConfig16+

Describes the virtual screen parameters.

System capability: SystemCapability.Window.SessionManager

NameTypeRead-OnlyOptionalDescription
namestringNoNoName of the virtual screen, which can be customized.
widthnumberNoNoWidth of the virtual screen, in px. The value must be a positive integer.
heightnumberNoNoHeight of the virtual screen, in px. The value must be a positive integer.
densitynumberNoNoDensity of the virtual screen, in px. The value is a floating point number.
surfaceIdstringNoNoSurface ID of the virtual screen, which can be customized.

display.getDisplayByIdSync12+

getDisplayByIdSync(displayId: number): Display

Obtains a Display object based on the display ID.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
displayIdnumberYesDisplay ID. The value must be an integer greater than or equal to 0. An object can be obtained only when the passed-in display ID is correct. You can use the value of the displayId property in WindowProperties as the input parameter.

Return value

TypeDescription
DisplayDisplay object.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2. Incorrect parameter types. 3. Parameter verification failed.
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let displayClass: display.Display|null = null;

try {
  // Use the value of the displayId property in WindowProperties as the input parameter.
  let displayId = 0; 
  displayClass = display.getDisplayByIdSync(displayId);
} catch (exception) {
  console.error(`Failed to get display. Code: ${exception.code}, message: ${exception.message}`);
}

display.getAllDisplayPhysicalResolution12+

getAllDisplayPhysicalResolution(): Promise<Array<DisplayPhysicalResolution>>

Obtains the display mode of the current foldable device and the corresponding physical screen resolution information.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Return value

TypeDescription
Promise<Array<DisplayPhysicalResolution>>Promise used to return all the DisplayPhysicalResolution objects.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let promise = display.getAllDisplayPhysicalResolution();
promise.then((resolutionObjects) => {
  console.info('Obtaining physical resolution length: ' + resolutionObjects.length);
  for (let i = 0; i < resolutionObjects.length; i++) {
     console.info(`resolutionObjects[${i}].foldDisplayMode: ${resolutionObjects[i].foldDisplayMode}`);
     console.info(`resolutionObjects[${i}].physicalWidth: ${resolutionObjects[i].physicalWidth}`); 
     console.info(`resolutionObjects[${i}].physicalHeight: ${resolutionObjects[i].physicalHeight}`); 
  }
}).catch((err: BusinessError) => {
  console.error(`Failed to obtain physical resolution. Code: ${err.code}, message: ${err.message}`);
});

display.getDefaultDisplaySync9+

getDefaultDisplaySync(): Display

Obtains the default display object. This API returns the result synchronously.

System capability: SystemCapability.WindowManager.WindowManager.Core

Atomic service API: This API can be used in atomic services since API version 11.

Return value

TypeDescription
DisplayDefault display object.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { display } from '@kit.ArkUI';

let displayClass: display.Display|null = null;

displayClass = display.getDefaultDisplaySync();

display.getPrimaryDisplaySync14+

getPrimaryDisplaySync(): Display

Obtains the information about the primary display. For devices other than 2-in-1 devices, the Display object obtained is the built-in screen. For 2-in-1 devices with an external screen, the Display object obtained is the primary screen. For 2-in-1 devices without an external screen, the Display object obtained is the built-in screen.

System capability: SystemCapability.WindowManager.WindowManager.Core

Atomic service API: This API can be used in atomic services since API version 14.

Return value

TypeDescription
DisplayDisplay object of the primary screen.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { display } from '@kit.ArkUI';

let displayClass: display.Display|null = null;

displayClass = display.getPrimaryDisplaySync();

display.getAllDisplays9+

getAllDisplays(callback: AsyncCallback<Array<Display>>): void

Obtains all display objects. This API uses an asynchronous callback to return the result.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<Display>>YesCallback used to return all the display objects.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let displayClass: Array<display.Display> = [];
display.getAllDisplays((err: BusinessError, data: Array<display.Display>) => {
  displayClass = data;
  const errCode: number = err.code;
  if (errCode) {
    console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
});

display.getAllDisplays9+

getAllDisplays(): Promise<Array<Display>>

Obtains all display objects. This API uses a promise to return the result.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Return value

TypeDescription
Promise<Array<Display>>Promise used to return all the display objects.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let displayClass: Array<display.Display> =[];
let promise: Promise<Array<display.Display>> = display.getAllDisplays();
promise.then((data: Array<display.Display>) => {
  displayClass = data;
  console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`);
});

display.on('add'|'remove'|'change')

on(type: 'add'|'remove'|'change', callback: Callback<number>): void

Subscribes to display changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type.
- add, indicating the display addition event. Example: event that a display is connected.
- remove, indicating the display removal event. Example: event that a display is disconnected.
- change, indicating the display change event. Example: event that the display orientation is changed.
callbackCallback<number>YesCallback used to return the ID of the display, which is an integer.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.

Example

import { Callback } from '@kit.BasicServicesKit';

let callback: Callback<number> = (data: number) => {
  console.info('Listening enabled. Data: ' + JSON.stringify(data));
};

display.on("add", callback);

display.off('add'|'remove'|'change')

off(type: 'add'|'remove'|'change', callback?: Callback<number>): void

Unsubscribes from display changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
typestringYesEvent type.
- add, indicating the display addition event. Example: event that a display is connected.
- remove, indicating the display removal event. Example: event that a display is disconnected.
- change, indicating the display change event. Example: event that the display orientation is changed.
callbackCallback<number>NoCallback used to return the ID of the display, which is an integer. If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.

Example


// Unregister all the callbacks that have been registered through on().
display.off("remove");

let callback: Callback<number> = (data: number) => {
  console.info('Succeeded in unregistering the callback for display remove. Data: ' + JSON.stringify(data))
};
// Unregister the specified callback.
display.off('remove', callback);

display.isFoldable10+

isFoldable(): boolean

Checks whether the current device is foldable.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
booleanReturns true if the device is foldable, and returns false otherwise.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let ret: boolean = false;
ret = display.isFoldable();

display.getFoldStatus10+

getFoldStatus(): FoldStatus

Obtains the fold status of the foldable device.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
FoldStatusFold status of the device.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let data: display.FoldStatus = display.getFoldStatus();
console.info('Succeeded in obtaining fold status. Data: ' + JSON.stringify(data));

display.getFoldDisplayMode10+

getFoldDisplayMode(): FoldDisplayMode

Obtains the display mode of the foldable device. This API is unavailable for 2-in-1 devices.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
FoldDisplayModeDisplay mode of the device.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let data: display.FoldDisplayMode = display.getFoldDisplayMode();
console.info('Succeeded in obtaining fold display mode. Data: ' + JSON.stringify(data));

display.getCurrentFoldCreaseRegion10+

getCurrentFoldCreaseRegion(): FoldCreaseRegion

Obtains the crease region of the foldable device in the current display mode.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
FoldCreaseRegionCrease region of the device.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let data: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion();
console.info('Succeeded in obtaining current fold crease region. Data: ' + JSON.stringify(data));

display.on('foldStatusChange')10+

on(type: 'foldStatusChange', callback: Callback<FoldStatus>): void

Subscribes to fold status change events of the foldable device.

To subscribe to display mode change events of foldable devices, use display.on('foldDisplayModeChange').

The two are different. In terms of time sequence, the fold status changes first, and the bottom layer matches the display mode status based on the fold status.

To check whether the content is displayed on the inner or outer screen of the foldable device, use display.on('foldDisplayModeChange').

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldStatusChange' is triggered when the fold status of the device changes.
callbackCallback<FoldStatus>YesCallback used to return the fold status.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';

/**
 * The callback parameter used for subscription must be passed as an object.
 * If an anonymous function is used for registration, a new underlying object is created each time the function is called, causing memory leakage.
*/
let callback: Callback<display.FoldStatus> = (data: display.FoldStatus) => {
  console.info('Listening enabled. Data: ' + JSON.stringify(data));
};
display.on('foldStatusChange', callback);

display.off('foldStatusChange')10+

off(type: 'foldStatusChange', callback?: Callback<FoldStatus>): void

Unsubscribes from fold status change events of the foldable device.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldStatusChange' is triggered when the fold status of the device changes.
callbackCallback<FoldStatus>NoCallback used to return the fold status. If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example


// Unregister all the callbacks that have been registered through on().
display.off('foldStatusChange');

let callback: Callback<display.FoldStatus> = (data: display.FoldStatus) => {
  console.info('unregistering FoldStatus changes callback. Data: ' + JSON.stringify(data));
};
// Unregister the specified callback.
display.off('foldStatusChange', callback);

display.on('foldAngleChange')12+

on(type: 'foldAngleChange', callback: Callback<Array<number>>): void

Subscribes to folding angle change events of the foldable device. Note that there are two folding angles for dual-fold axis devices. When oriented with the charging port at the bottom, the hinges are identified from right to left as the first and second fold axes, respectively.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldAngleChange' is triggered when the folding angle of the device changes.
callbackCallback<Array<number>>YesCallback used to return the folding angle (0–180 degrees). For dual-fold axis devices, the array contains two angles. The first value represents the folding angle of the first fold axis, while the second value represents the folding angle of the second fold axis.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';

let callback: Callback<Array<number>> = (angles: Array<number>) => {
  console.info('Listening fold angles length: ' + angles.length);
};
display.on('foldAngleChange', callback);

display.off('foldAngleChange')12+

off(type: 'foldAngleChange', callback?: Callback<Array<number>>): void

Unsubscribes from folding angle change events of the foldable device.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldAngleChange' is triggered when the folding angle of the device changes.
callbackCallback<Array<number>>NoCallback used to return the folding angle (0–180 degrees). If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example


// Unregister all the callbacks that have been registered through on().
display.off('foldAngleChange');

let callback: Callback<Array<number>> = (angles: Array<number>) => {
  console.info('Listening fold angles length: ' + angles.length);
};
// Unregister the specified callback.
display.off('foldAngleChange', callback);

display.on('captureStatusChange')12+

on(type: 'captureStatusChange', callback: Callback<boolean>): void

Subscribes to screen capture, casting, or recording status changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'captureStatusChange' is triggered when the screen capture, casting, or recording status changes.
callbackCallback<boolean>YesCallback used to return the status change during screen capture, casting, or recording. The value true means the start of screen casting or recording, and false means the end of screen casting or recording. In the case of screen capture, only true is returned once.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';

let callback: Callback<boolean> = (captureStatus: boolean) => {
  console.info('Listening capture status: ' + captureStatus);
};
display.on('captureStatusChange', callback);

display.off('captureStatusChange')12+

off(type: 'captureStatusChange', callback?: Callback<boolean>): void

Unsubscribes from screen capture, casting, or recording status changes.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'captureStatusChange' is triggered when the screen capture, casting, or recording status changes.
callbackCallback<boolean>NoCallback used to return the status change during screen capture, casting, or recording. The value true means the start of screen casting or recording, and false means the end of screen casting or recording. In the case of screen capture, only true is returned once. If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example


// Unregister all the callbacks that have been registered through on().
display.off('captureStatusChange');

let callback: Callback<boolean> = (captureStatus: boolean) => {
  console.info('Listening capture status: ' + captureStatus);
};
// Unregister the specified callback.
display.off('captureStatusChange', callback);

display.isCaptured12+

isCaptured(): boolean

Checks whether the display is being captured, projected, or recorded.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
booleantrue: The display is being captured, projected, or recorded.
false: The display is not being captured, projected, or recorded.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400003This display manager service works abnormally.

Example

import { display } from '@kit.ArkUI';

let ret: boolean = false;
ret = display.isCaptured();

display.on('foldDisplayModeChange')10+

on(type: 'foldDisplayModeChange', callback: Callback<FoldDisplayMode>): void

Subscribes to display mode change events of the foldable device. This API is unavailable for 2-in-1 devices.

To subscribe to fold status change events of foldable devices, use display.on('foldStatusChange').

The two are different. In terms of time sequence, the fold status changes first, and the bottom layer matches the display mode status based on the fold status.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldDisplayModeChange' is triggered when the display mode of the device changes.
callbackCallback<FoldDisplayMode>YesCallback used to return the display mode.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';

/**
 * The callback parameter used for subscription must be passed as an object.
 * If an anonymous function is used for registration, a new underlying object is created each time the function is called, causing memory leakage.
*/
let callback: Callback<display.FoldDisplayMode> = (data: display.FoldDisplayMode) => {
  console.info('Listening enabled. Data: ' + JSON.stringify(data));
}; 
display.on('foldDisplayModeChange', callback);

display.off('foldDisplayModeChange')10+

off(type: 'foldDisplayModeChange', callback?: Callback<FoldDisplayMode>): void

Unsubscribes from display mode change events of the foldable device. This API is unavailable for 2-in-1 devices.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'foldDisplayModeChange' is triggered when the display mode of the device changes.
callbackCallback<FoldDisplayMode>NoCallback used to return the display mode. If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
1400003This display manager service works abnormally.

Example


// Unregister all the callbacks that have been registered through on().
display.off('foldDisplayModeChange');

let callback: Callback<display.FoldDisplayMode> = (data: display.FoldDisplayMode) => {
  console.info('unregistering FoldDisplayMode changes callback. Data: ' + JSON.stringify(data));
};
// Unregister the specified callback.
display.off('foldDisplayModeChange', callback);

display.getDefaultDisplay(deprecated)

getDefaultDisplay(callback: AsyncCallback<Display>): void

Obtains the default display object. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use getDefaultDisplaySync() instead.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Display>YesCallback used to return the default display object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let displayClass: display.Display|null = null;
display.getDefaultDisplay((err: BusinessError, data: display.Display) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error(`Failed to obtain the default display object. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
  displayClass = data;
});

display.getDefaultDisplay(deprecated)

getDefaultDisplay(): Promise<Display>

Obtains the default display object. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use getDefaultDisplaySync() instead.

System capability: SystemCapability.WindowManager.WindowManager.Core

Return value

TypeDescription
Promise<Display>Promise used to return the default display object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let displayClass: display.Display|null = null;
let promise: Promise<display.Display> = display.getDefaultDisplay();
promise.then((data: display.Display) => {
  displayClass = data;
  console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`Failed to obtain the default display object. Code: ${err.code}, message: ${err.message}`);
});

display.getAllDisplay(deprecated)

getAllDisplay(callback: AsyncCallback<Array<Display>>): void

Obtains all display objects. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use getAllDisplays() instead.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<Display>>YesCallback used to return all the display objects.

Example

import { BusinessError } from '@kit.BasicServicesKit';

display.getAllDisplay((err: BusinessError, data: Array<display.Display>) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
});

display.getAllDisplay(deprecated)

getAllDisplay(): Promise<Array<Display>>

Obtains all display objects. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use getAllDisplays() instead.

System capability: SystemCapability.WindowManager.WindowManager.Core

Return value

TypeDescription
Promise<Array<Display>>Promise used to return all the display objects.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let promise: Promise<Array<display.Display>> = display.getAllDisplay();
promise.then((data: Array<display.Display>) => {
  console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`);
});

display.createVirtualScreen16+

createVirtualScreen(config:VirtualScreenConfig): Promise<number>

Creates a virtual screen. This API uses a promise to return the result.

System capability: SystemCapability.Window.SessionManager

Required permissions: ohos.permission.ACCESS_VIRTUAL_SCREEN

Parameters

NameTypeMandatoryDescription
configVirtualScreenConfigYesVirtual screen parameters.

Return value

TypeDescription
Promise<number>Promise used to return the ID of the created virtual screen.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported.function createVirtualScreen can not work correctly due to limited device capabilities.
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';

class VirtualScreenConfig {
  name : string = '';
  width : number = 0;
  height : number = 0;
  density : number = 0;
  surfaceId : string = '';
}

let config : VirtualScreenConfig = {
  name: 'screen01',
  width: 1080,
  height: 2340,
  density: 2,
  surfaceId: ''
};

display.createVirtualScreen(config).then((screenId: number) => {
  console.info('Succeeded in creating the virtual screen. Data: ' + JSON.stringify(screenId));
}).catch((err: BusinessError) => {
  console.error(`Failed to create the virtual screen. Code:${err.code},message is ${err.message}`);
});

display.destroyVirtualScreen16+

destroyVirtualScreen(screenId:number): Promise<void>

Destroys a virtual screen. This API uses a promise to return the result.

System capability: SystemCapability.Window.SessionManager

Required permissions: ohos.permission.ACCESS_VIRTUAL_SCREEN

Parameters

NameTypeMandatoryDescription
screenIdnumberYesScreen ID, which must match the ID of the virtual screen created by calling the createVirtualScreen() API. This parameter only accepts integer values.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported.function destroyVirtualScreen can not work correctly due to limited device capabilities.
1400001Invalid display or screen.
1400003This display manager service works abnormally.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let screenId: number = 1;
display.destroyVirtualScreen(screenId).then(() => {
  console.info('Succeeded in destroying the virtual screen.');
}).catch((err: BusinessError) => {
  console.error(`Failed to destroy the virtual screen.Code:${err.code},message is ${err.message}`);
});

display.setVirtualScreenSurface16+

setVirtualScreenSurface(screenId:number, surfaceId: string): Promise<void>

Sets a surface ID for a virtual screen. This API uses a promise to return the result.

System capability: SystemCapability.Window.SessionManager

Required permissions: ohos.permission.ACCESS_VIRTUAL_SCREEN

Parameters

NameTypeMandatoryDescription
screenIdnumberYesScreen ID, which must match the ID of the virtual screen created by calling the createVirtualScreen() API. This parameter only accepts integer values.
surfaceIdstringYesSurface ID of the virtual screen. The value can be customized.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported.function setVirtualScreenSurface can not work correctly due to limited device capabilities.
1400001Invalid display or screen.
1400003This display manager service works abnormally.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let screenId: number = 1;
let surfaceId: string = '2048';
display.setVirtualScreenSurface(screenId, surfaceId).then(() => {
  console.info('Succeeded in setting the surface for the virtual screen.');
}).catch((err: BusinessError) => {
  console.error(`Failed to set the surface for the virtual screen. Code:${err.code},message is ${err.message}`);
});

display.makeUnique16+

makeUnique(screenId:number): Promise<void>

Sets the screen to independent display mode. This API uses a promise to return the result.

System capability: SystemCapability.Window.SessionManager

Required permissions: ohos.permission.ACCESS_VIRTUAL_SCREEN

Parameters

NameTypeMandatoryDescription
screenIdnumberYesID of the screen. Each ID must be an integer greater than 0; otherwise, error code 401 is returned.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
201Permission verification failed. The application does not have the permission required to call the API.
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
801Capability not supported.function makeUnique can not work correctly due to limited device capabilities.
1400001Invalid display or screen.
1400003This display manager service works abnormally.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let screenId: number = 0;
display.makeUnique(screenId).then(() => {
  console.info('Succeeded in making unique screens.');
}).catch((err: BusinessError) => {
  console.error(`Failed to make unique screens. Code:${err.code},message is ${err.message}`);
});

Display

Implements a Display instance, with properties and APIs defined.

Before calling any API in Display, you must use getAllDisplays() or getDefaultDisplaySync() to obtain a Display instance.

Properties

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeRead-OnlyOptionalDescription
idnumberYesNoID of the display. The value is an integer greater than or equal to 0.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
namestringYesNoName of the display.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
alivebooleanYesNoWhether the display is alive. The value true means that the display is alive, and false means the opposite.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
stateDisplayStateYesNoState of the display.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
refreshRatenumberYesNoRefresh rate of the display, in hz. The value is an integer.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
rotationnumberYesNoClockwise rotation angle of the display.
The value 0 indicates that the display rotates clockwise by 0°.
The value 1 indicates that the display rotates clockwise by 90°.
The value 2 indicates that the display rotates clockwise by 180°.
The value 3 indicates that the display rotates clockwise by 270°.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 11.
widthnumberYesNoWidth of the display, in px. The value is an integer.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 11.
heightnumberYesNoHeight of the display, in px. The value is an integer.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 11.
densityDPInumberYesNoPhysical pixel density of the display, that is, the number of pixels per inch. The value is a floating point number, in px. Generally, the value is 160.0 or 480.0. The actual value depends on the optional values provided by the device in use.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
orientation10+OrientationYesNoOrientation of the display.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
densityPixelsnumberYesNoLogical pixel density of the display, which is the scaling coefficient between physical pixels and logical pixels. The calculation method is as follows:
densityPixels
The value is a floating point number and is restricted by the range of densityDPI. The value range is [0.5, 4.0]. Generally, the value is 1.0 or 3.0. The actual value depends on the density DPI provided by the device in use.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 11.
scaledDensitynumberYesNoScaling factor for fonts displayed on the display. The value must be a floating point number. Generally, the value is the same as that of densityPixels.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
xDPInumberYesNoExact physical pixels per inch of the display in the X dimension. The value must be a floating point number.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
yDPInumberYesNoExact physical pixels per inch of the display in the Y dimension. The value must be a floating point number.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
colorSpaces11+Array<colorSpaceManager.ColorSpace>YesNoAll color spaces supported by the display.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
hdrFormats11+Array<hdrCapability.HDRFormat>YesNoAll HDR formats supported by the display.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
availableWidth12+numberYesNoWidth of the available area on a 2-in-1 device, in px. The value is an integer greater than 0.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
availableHeight12+numberYesNoHeight of the available area on a 2-in-1 device, in px. The value is an integer greater than 0.
System capability: SystemCapability.WindowManager.WindowManager.Core
Atomic service API: This API can be used in atomic services since API version 12.
screenShape18+ScreenShapeYesYesScreen shape of the display. The default value is RECTANGLE.
Atomic service API: This API can be used in atomic services since API version 18.
sourceMode19+DisplaySourceModeYesYesDisplay mode for screen content.
System capability: SystemCapability.Window.SessionManager
Atomic service API: This API can be used in atomic services since API version 19.
x19+numberYesYesX coordinate of the upper left corner of the screen relative to the origin, which is the upper left corner of the primary screen, measured in px. The value is an integer. It is returned only when DisplaySourceMode is set to MAIN or EXTEND.
System capability: SystemCapability.Window.SessionManager
Atomic service API: This API can be used in atomic services since API version 19.
y19+numberYesYesY coordinate of the upper left corner of the screen relative to the origin, which is the upper left corner of the primary screen, measured in px. The value is an integer. It is returned only when DisplaySourceMode is set to MAIN or EXTEND.
System capability: SystemCapability.Window.SessionManager
Atomic service API: This API can be used in atomic services since API version 19.

getCutoutInfo9+

getCutoutInfo(callback: AsyncCallback<CutoutInfo>): void

Obtains the cutout information of the display. This API uses an asynchronous callback to return the result. You are advised not to use the cutout area during application layout.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<CutoutInfo>YesCallback used to return the CutoutInfo object.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let displayClass: display.Display|null = null;
displayClass = display.getDefaultDisplaySync();

displayClass.getCutoutInfo((err: BusinessError, data: display.CutoutInfo) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error(`Failed to get cutoutInfo. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data));
});

getCutoutInfo9+

getCutoutInfo(): Promise<CutoutInfo>

Obtains the cutout information of the display. This API uses a promise to return the result. You are advised not to use the cutout area during application layout.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.WindowManager.WindowManager.Core

Return value

TypeDescription
Promise<CutoutInfo>Promise used to return the CutoutInfo object.

Error codes

For details about the error codes, see Display Error Codes.

IDError Message
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let displayClass: display.Display|null = null;
displayClass = display.getDefaultDisplaySync();
let promise: Promise<display.CutoutInfo> = displayClass.getCutoutInfo();
promise.then((data: display.CutoutInfo) => {
  console.info('Succeeded in getting cutoutInfo. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error(`Failed to obtain all the display objects. Code: ${err.code}, message: ${err.message}`);
});

getAvailableArea12+

getAvailableArea(): Promise<Rect>

Obtains the available area of the display of the current device. This API uses a promise to return the result.

Only 2-in-1 devices are supported.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Return value

TypeDescription
Promise<Rect>Promise used to return the available area, which is a rectangle.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
801Capability not supported. Failed to call the API due to limited device capabilities.
1400001Invalid display or screen.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let displayClass: display.Display|null = null;
try {
  displayClass = display.getDefaultDisplaySync();
  let promise = displayClass.getAvailableArea();
  promise.then((data) => {
    console.info('Succeeded get the available area in this display. data: ' + JSON.stringify(data));
  }).catch((err: BusinessError) => {
    console.error(`Failed to get the available area in this display. Code: ${err.code}, message: ${err.message}`);
  })
} catch (exception) {
  console.error(`Failed to obtain the default display object. Code: ${exception.code}, message: ${exception.message}`);
}

on('availableAreaChange')12+

on(type: 'availableAreaChange', callback: Callback<Rect>): void

Subscribes to changes of the available area on the display of the current device. This API uses an asynchronous callback to return the result.

Only 2-in-1 devices are supported.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'availableAreaChange' is triggered when the available area of the display changes.
callbackCallback<Rect>YesCallback used to return the new available area.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported. Failed to call the API due to limited device capabilities.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let callback: Callback<display.Rect> = (data: display.Rect) => {
  console.info('Listening enabled. Data: ' + JSON.stringify(data));
};
let displayClass: display.Display|null = null;
try {
  displayClass = display.getDefaultDisplaySync();
  displayClass.on("availableAreaChange", callback);
} catch (exception) {
  console.error(`Failed to register callback. Code: ${exception.code}, message: ${exception.message}`);
}

off('availableAreaChange')12+

off(type: 'availableAreaChange', callback?: Callback<Rect>): void

Unsubscribes from changes of the available area on the display of the current device.

Only 2-in-1 devices are supported.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Window.SessionManager

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The event 'availableAreaChange' is triggered when the available area of the display changes.
callbackCallback<Rect>NoCallback used to return the new available area. If this parameter is not specified, all subscriptions to the specified event are canceled.

Error codes

For details about the error codes, see Universal Error Codes and Display Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported. Failed to call the API due to limited device capabilities.
1400003This display manager service works abnormally.

Example

import { Callback } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

let callback: Callback<display.Rect> = (data: display.Rect) => {
  console.info('Listening enabled. Data: ' + JSON.stringify(data));
};
let displayClass: display.Display|null = null;
try {
  displayClass = display.getDefaultDisplaySync();
  displayClass.off("availableAreaChange", callback);
} catch (exception) {
  console.error(`Failed to unregister callback. Code: ${exception.code}, message: ${exception.message}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI

harmony 鸿蒙ARKUI_TextPickerCascadeRangeContent

harmony 鸿蒙ARKUI_TextPickerRangeContent

harmony 鸿蒙ArkUI_AnimateCompleteCallback

harmony 鸿蒙ArkUI_AttributeItem

harmony 鸿蒙ArkUI_ColorStop

harmony 鸿蒙ArkUI_ContextCallback

harmony 鸿蒙ArkUI_EventModule

harmony 鸿蒙ArkUI_ExpectedFrameRateRange

harmony 鸿蒙ArkUI_IntOffset

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/vOYyI2