private boolean isScreenOn() {
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
     DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
     boolean screenOn = false;
     for (Display display : dm.getDisplays()) {
       if (display.getState() != Display.STATE_OFF) {
         screenOn = true;
       }
     }
     return screenOn;
   } else {
     PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
     //noinspection deprecation
     return pm.isScreenOn();
   }
 }
  private boolean isScreenOn() {

    // Take special care for API20+
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
      DisplayManager dm = (DisplayManager) mContext.getSystemService(mContext.DISPLAY_SERVICE);

      // We iterate through all available displays
      for (Display display : dm.getDisplays()) {
        if (display.getState() != Display.STATE_OFF) return false;
      }
      // If we are here, all displays are on;
      return true;

    } else {
      PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);

      return !pm.isScreenOn();
    }
  }