Android Display Manager

The Android Display Manager is a system service that manages the display devices on an Android device. It provides functionality for controlling and managing the display, including handling display configuration changes, accessing display information, and controlling display brightness.

Display Manager Overview

The DisplayManager class is the entry point for interacting with the Display Manager service. It provides methods for querying and controlling display devices. To obtain an instance of the DisplayManager, you can use the Context object:

DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);

Display Devices

A display device represents a physical screen attached to the Android device. The Display class represents a display device and provides methods for accessing its properties, such as its size, density, and rotation.

To get a list of all available displays, you can use the getDisplays() method:

Display[] displays = displayManager.getDisplays();

The returned array contains all displays, including the default display. You can retrieve the default display using the getDisplay() method:

Display defaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);

Display Information

The Display class also provides methods for accessing display information, such as the display size, resolution, and density.

To get the display size, you can use the getSize() method:

Point size = new Point();
defaultDisplay.getSize(size);
int width = size.x;
int height = size.y;

To get the display resolution, you can use the getRealSize() method:

Point realSize = new Point();
defaultDisplay.getRealSize(realSize);
int width = realSize.x;
int height = realSize.y;

To get the display density, you can use the getDensity() method:

float density = defaultDisplay.getDensity();

Display Configuration Changes

The Display Manager handles display configuration changes, such as screen rotation, density changes, and display mode changes. It sends a broadcast message when a configuration change occurs, and you can register a BroadcastReceiver to receive these events.

To register a receiver for display configuration changes, you can use the registerDisplayListener() method:

displayManager.registerDisplayListener(displayListener, null);

The displayListener is an instance of DisplayManager.DisplayListener, which requires implementing the onDisplayAdded(), onDisplayRemoved(), and onDisplayChanged() methods to handle the corresponding events.

private DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener() {
    @Override
    public void onDisplayAdded(int displayId) {
        // Handle display added event
    }

    @Override
    public void onDisplayRemoved(int displayId) {
        // Handle display removed event
    }

    @Override
    public void onDisplayChanged(int displayId) {
        // Handle display changed event
    }
};

Display Brightness

The Display Manager also provides methods for controlling the display brightness programmatically. To set the display brightness, you can use the setTemporaryBrightness() method:

displayManager.setTemporaryBrightness(displayId, brightness);

The displayId parameter specifies the display to adjust brightness for, and the brightness parameter represents the desired brightness level. The brightness level is a float value between 0.0 and 1.0, where 0.0 is the lowest brightness and 1.0 is the highest.

Conclusion

In this article, we have explored the Android Display Manager and its functionalities. We have learned how to access display devices, retrieve display information, handle display configuration changes, and control display brightness. The Display Manager provides powerful features for managing and controlling the display on Android devices, enabling developers to create better user experiences.

For more information, refer to the official Android documentation on [DisplayManager](

Note: The code examples in this article are written in Java.