Android disable screen saver

I want to turn off the screen saver while my application is running. How can I do that? Where is the best way to disable / enable the screen saver? in the first action? in application.java?

+6
source share
2 answers

The manifest must specify the permission to block tracking.

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

Then in the activity, use the following to turn on the screen during operation.

 getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); 

Remember that unnecessarily holding the screen from excessive exhaustion of power from the user device.

+14
source

You should also add:

import android.view.WindowManager.LayoutParams;

+1
source

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


All Articles