Please call the following two functions to turn off the screen, as your code is incompatible.
From Documents:
public void goToSleep (long time)
Added to API level 1. Forces the device to enter sleep mode.
Overrides all tracking locks that are stored. This is what happens when you press the power key to turn off the screen. Requires DEVICE_POWER permission.
public void wakeUp (long time)
Added to API Level 17 Causes the device to wake up from sleep.
If the device is currently sleeping, wakes up, otherwise nothing happens. This is what happens when you press the power key to turn on the screen.
Requires DEVICE_POWER permission.
source share