Three ways for Android to keep the screen always bright: android always bright
I haven't written a Blog for a long time, and I have to implement similar functions recently. It's not very convenient to find a blog every time. I 'd like to record it on my Blog!
There are three methods:
1. Apply for screen lock
Pm = (PowerManager) context. getSystemService (Context. POWER_SERVICE );
// Obtain the power manager object
Wl = pm. newWakeLock (PowerManager. ACQUIRE_CAUSES_WAKEUP | PowerManager. FULL_WAKE_LOCK, "TEST ");
Wl. acquire ();
Release when not in use
This is a bit of water, and you need to spend time researching it, including cpu wake lock and so on.
2. Use the flag attribute of the Window
GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_KEEP_SCREEN_ON, WindowManager. LayoutParams. FLAG_KEEP_SCREEN_ON );
SetContentView (R. layout. xmltext); // It must be earlier
This attribute is actually used by Google to replace method 1.
3. Recommended. This method is the easiest and requires no code modification.
Android: keepScreenOn = "true"
As long as the control basically has this property, the code can also be set