Three ways for Android to keep the screen always bright: android always bright

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.