Skip to content

Most visited

Recently visited

navigation

ScreenManager

ScreenManager

public class ScreenManager
extends Object

java.lang.Object
   ↳ com.google.android.things.device.ScreenManager


This class provides access to device settings related to the display. This includes the following operations:

  • Screen brightness
  • Default orientation
  • Display inactivity timeout

To control device settings using ScreenManager, obtain an instance of the class and set the properties appropriate for your app.

 ScreenManager screenManager = new ScreenManager(Display.DEFAULT_DISPLAY);
 // Set brightness to a fixed value
 screenManager.setBrightnessMode(ScreenManager.BRIGHTNESS_MODE_MANUAL);
 screenManager.setBrightness(255); //Max it out.

 // Lock orientation in portrait mode
 screenManager.lockRotation(ScreenManager.ROTATION_90);

Current values for all display-related settings can be read from Settings.System.

Summary

Constants

int BRIGHTNESS_MODE_AUTOMATIC

The system will change brightness depending on lux sensor inputs

int BRIGHTNESS_MODE_MANUAL

Users must change brightness themselves

int ROTATION_0

0 degree rotation

int ROTATION_180

180 degree rotation

int ROTATION_270

270 degree rotation

int ROTATION_90

90 degree rotation

int ROTATION_CURRENT

The current degree of rotation

Public constructors

ScreenManager(int displayId)

Creates a ScreenManager from the provided display id.

Public methods

void lockRotation(int rotation)

Locks the rotation of the screen to the specified rotation.

void setBrightness(int brightness)

Sets the screen backlight brightness.

void setBrightnessMode(int brightnessMode)

Sets the brightness mode.

void setDisplayDensity(int density)

Sets the display density of the screen.

void setFontScale(float scalingFactor)

Sets the scale by which font sizes are multiplied.

void setScreenOffTimeout(long duration, TimeUnit unit)

Sets the duration of inactivity before the device goes to sleep.

void unlockRotation()

Unlocks the rotation of the screen.

Inherited methods

From class java.lang.Object

Constants

BRIGHTNESS_MODE_AUTOMATIC

int BRIGHTNESS_MODE_AUTOMATIC

The system will change brightness depending on lux sensor inputs

Constant Value: 1 (0x00000001)

BRIGHTNESS_MODE_MANUAL

int BRIGHTNESS_MODE_MANUAL

Users must change brightness themselves

Constant Value: 0 (0x00000000)

ROTATION_0

int ROTATION_0

0 degree rotation

Constant Value: 0 (0x00000000)

ROTATION_180

int ROTATION_180

180 degree rotation

Constant Value: 2 (0x00000002)

ROTATION_270

int ROTATION_270

270 degree rotation

Constant Value: 3 (0x00000003)

ROTATION_90

int ROTATION_90

90 degree rotation

Constant Value: 1 (0x00000001)

ROTATION_CURRENT

int ROTATION_CURRENT

The current degree of rotation

Constant Value: -1 (0xffffffff)

Public constructors

ScreenManager

ScreenManager (int displayId)

Creates a ScreenManager from the provided display id.

Parameters
displayId int: the display id of the Display that all method calls will affect.

Public methods

lockRotation

void lockRotation (int rotation)

Locks the rotation of the screen to the specified rotation.

Parameters
rotation int: value to specify the degrees of rotation (eg. ROTATION_0).
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

setBrightness

void setBrightness (int brightness)

Sets the screen backlight brightness.

Parameters
brightness int: level of brightness between 0 and 255.
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

setBrightnessMode

void setBrightnessMode (int brightnessMode)

Sets the brightness mode. This should be either BRIGHTNESS_MODE_MANUAL or BRIGHTNESS_MODE_AUTOMATIC.

Parameters
brightnessMode int: the brightness mode to be set.
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

setDisplayDensity

void setDisplayDensity (int density)

Sets the display density of the screen.

Parameters
density int: the density to set in dpi.
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

setFontScale

void setFontScale (float scalingFactor)

Sets the scale by which font sizes are multiplied.

Parameters
scalingFactor float: the scaling factor for fonts.
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

setScreenOffTimeout

void setScreenOffTimeout (long duration, 
                TimeUnit unit)

Sets the duration of inactivity before the device goes to sleep.

Parameters
duration long: the duration of inactivity before the device should go to sleep.
unit TimeUnit: the unit of time for the duration.
Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.

unlockRotation

void unlockRotation ()

Unlocks the rotation of the screen.

Throws
IllegalStateException if the underlying system service is not ready.
RuntimeException if the underlying system service encountered an error.
SecurityException if the calling context does not have com.google.android.things.permission.MODIFY_SCREEN_SETTINGS permission.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)