Can't use PowerManager goToSleep APi in android

Hii felas, I created the application, and I need to call the phone in the screen saver mode, because I get the trigger ... I looked around and found out that PowerManager.java provides such a goToSleep API "

API Description.

Now my problem is that I need special permission to do this work, namely

" android.Manifest.permission.DEVICE_POWER " this permission is a level 2 permission, just declaring it in the manifest does not give me permission so now I have to run the application in the system thread (checked if it works if I do this) to get this permission is successful

can someone give me any advice or any other way how i can make this work without using my application (is there any other way to cause the same behavior

+4
source share
1 answer

At a certain brightness value, the screen turns off, so this should work:

WindowManager.LayoutParams lp = getWindow (). getAttributes (); lp.flags | = LayoutParams.FLAG_KEEP_SCREEN_ON;
lp.screenBrightness = 0;
. GetWindow () SetAttributes (LP);

-1
source

All Articles