How to call the event "screen_off", when running my app? for example 5 seconds after the start
Asked
Active
Viewed 734 times
2 Answers
1
in displayOffTime=5*1000;//5 seconds
following code will make screen off after 5 seconds
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, displayOffTime);

Rasel
- 15,499
- 6
- 40
- 50
-
more detail, please. how to call class Settings (I'm new to android) – Tim Jul 20 '11 at 10:16
-
This approach sets the time at which an idle screen turns off. It does not actively turn off the screen. – user462990 Aug 10 '12 at 11:03
0
This will turn the screen off for the specified amount of time:
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(int amountOfTime);

A. Abiri
- 10,750
- 4
- 30
- 31
-
It should be pointed out that this requires signature permission DEVICE_POWER, which most applications are unlikely to hold: http://stackoverflow.com/questions/5710971/android-what-permissions-required-to-call-powermanager-gotosleepn-put-device-i – Rupert Rawnsley Jun 18 '12 at 13:40