Example usage for android.view Display getState

List of usage examples for android.view Display getState

Introduction

In this page you can find the example usage for android.view Display getState.

Prototype

public int getState() 

Source Link

Document

Gets the state of the display, such as whether it is on or off.

Usage

From source file:com.mathi_amorim.emmanuel.metrictime.UpdateTimeService.java

public boolean isScreenOn() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
        boolean screenOn = false;
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                screenOn = true;//from w w  w  .  j  a v a  2  s .  c  om
            }
        }
        return screenOn;
    } else {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        return pm.isScreenOn();
    }
}