Lukap
Lukap

Reputation: 31963

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

Upvotes: 5

Views: 5664

Answers (1)

SERPRO
SERPRO

Reputation: 10067

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

Upvotes: 3

Related Questions