Android keeps the screen solid

Source: Internet
Author: User

Android keeps the screen always on, powermanager.wakelock use

Package com.hebaijun.wakelock;    import android.app.activity;  import  android.os.Bundle;  import android.os.PowerManager;    public  class wakelockactivity extends activity {       Powermanager.wakelock wakelock;      /** called when the  activity is first created. */       @Override        public void oncreate (bundle savedinstancestate)  {           super.oncreate (savedinstancestate);           setcontentview (R.layout.main);           wakeLock =  ((PowerManager) Getsystemservice (Power_service)). Newwakelock ( powermanager.screen_bright_wake_lock |  powermanager.on_after_release,  "Wakelockactivity");      }        @Override       protected void onpause ()  {           super.onpause ();           if  (wakelock != null)  {               wakelock.release ();           }      }       @Override        protected void onresume ()  {           super.onresume ();             Wakelock.acquire ();      }  }  

  

Need to add permissions in Androidmanifest.xml <uses-permission android:name= "Android.permission.WAKE_LOCK"/>

    • Screen_bright_wake_lock indicates that the screen is on and the keyboard is not lit.
    • On_after_release indicates that the release method continues to keep the screen lit until the default time-out after the black screen.
    • It is best to request a solid in the Onresume method and release it in the OnPause method.

Android keeps the screen solid

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.