1

How to call the event "screen_off", when running my app? for example 5 seconds after the start

Tim
  • 1,606
  • 2
  • 20
  • 32

2 Answers2

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
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