I am creating an android app which has functionality to sleep the device based on certain conditions and wake up based on some other conditions. Before API 21, there was a method powerManager.goToSleep()
in PowerManager
which used to do the trick. But, now the same method is not accessible anymore. Is there any other way to do that?
int defaultTurnOffTime = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 60000);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 1000);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, defaultTurnOffTime);
Above mentioned code is something I have got so far. But, it doesn't seem to work for me. Please suggest if there is any way to achieve the functionality.