Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off the screen in android

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

like image 810
Lukap Avatar asked Oct 24 '22 19:10

Lukap


1 Answers

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

like image 179
SERPRO Avatar answered Oct 27 '22 10:10

SERPRO