Turn: Android settings screen is not standby

Source: Internet
Author: User

This article was reproduced in: http://blog.csdn.net/yudajun/article/details/7748760

Android Settings Branch Standby there are two ways

The first is simply achieved by setting the WindowManager property:

In the Activity Oncreat () method, set the

GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_ SCREEN_ON);

The second implementation of PowerManager and Powermanager.wakelock using Android:

Add lock

Private voidAcquirewakelock () {if(WakeLock = =NULL) {LOGGER.D ("Acquiring Wake Lock"); PowerManager pm=(PowerManager) Getsystemservice (Context.power_service); WakeLock= Pm.newwakelock (Powermanager.screen_dim_wake_lock, This. GetClass (). Getcanonicalname ());              Wakelock.acquire (); }                }    //Release LockPrivate voidReleasewakelock () {if(WakeLock! =NULL&&Wakelock.isheld ())              {wakelock.release (); WakeLock=NULL; }        }  

The Acquirewakelock () method is called in the activity's onresume. The Releasewakelock () method is called in the activity's onpause. Use Activiy's life cycle to subtly make acquire () and release () pairs appear.

about int flags The effects of various types of locks on the CPU, screen, keyboard:

partial_wake_lock: Keep the CPU running, and the screen and keyboard lights may be off.

screen_dim_wake_lock: Keep the CPU running, allow the screen to be displayed but may be gray, allow to turn off the keyboard light

screen_bright_wake_lock: Keeps the CPU running, allowing the screen to be highlighted, allowing the keyboard light to be turned off

full_wake_lock: Keep the CPU running, keep the screen highlighted, and the keyboard lights remain bright

Don't forget it at last!

The operation to be powered requires that the app has permission to set power management in Androidmanifest.xml.

<uses-permission android:name= "Android.permission.WAKE_LOCK"/> You may also need <uses-permission android:name= " Android.permission.DEVICE_POWER "/>

Turn: Android settings screen is not standby

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: info-contact@alibabacloud.com 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.