Turn off screen in android

I google this, and there are many examples in handling even on_screen_of and on_screen_off, but I want to actually turn the screen on and off. Every search I did led me to handle an on and off event.

I want to have a button that when disabled will be disabled.

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

thanks

+4
source share
1 answer
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE); manager.goToSleep(int amountOfTime); 

You may also need this permission:

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

The answer is extracted from here.

+3
source

Source: https://habr.com/ru/post/1379988/


All Articles