5

I google this and there is a lot of examples in handling the even on_screen_of and on_screen_off, but I want to actually turn on and turn off the screen. Every search I made it lead me on handling the screen on and off event.

I want to have a button that when clicked will turn the screen off.

How can I do this, and what permissions do I need ? or I this is talked before please give me some useful link

Thanks

Lukap
  • 31,523
  • 64
  • 157
  • 244

1 Answers1

3
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(int amountOfTime);

You will probably need this permission too:

<uses-permission android:name="android.permission.WAKE_LOCK" />

Answer extracted from here

Community
  • 1
  • 1
SERPRO
  • 10,015
  • 8
  • 46
  • 63
  • 2
    it throws Neither user 10079 nor current process has android.permission.DEVICE_POWER. But in my manifest I provide the and still throws the exception, any ideas why ? – Lukap Nov 07 '11 at 12:34
  • 4
    The `DEVICE_POWER` permission can't be used by normal apps, they have to be signed as system apps. See [this question](http://stackoverflow.com/questions/5710971/android-what-permissions-required-to-call-powermanager-gotosleepn-put-device-i) and the links within the answers. –  Nov 07 '11 at 12:57