Introduction to Android Development-------screen light, keypad lock

Source: Internet
Author: User

Mobile application development, often need to keep the phone screen constantly lit, or when the screen is locked, unlocked.
Android System (of course I developed the Android system version is 4.0) through the context also have translated to content, get the Window object, then you can set the current screen parameters.

The management of the screen lights, need to use the PowerManager object, through the system service to obtain the object. and the specific operation needs Android.os.PowerManager.WakeLock object to operate,

Look at the actual example. After execution, the resource of the operand needs to be freed. Attached Newwakelock Gets the parameter interpretation table for the action object.

Screen
Flag Value CPU Keyboard
Partial_wake_lock on* Off Off
Screen_dim_wake_lock On Dim Off
Screen_bright_wake_lock On Bright Off
Full_wake_lock On Bright

Bright

Of course, for PowerManager to learn more, still need to look at official documents.

Instance code:

1 //Unlock the keyboard to keep the screen light on. Settings are valid before Setcontentview. 2 GetWindow (). Addflags (3 WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD4|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED5|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);6PowerManager pm =(PowerManager) Getsystemservice (context.power_service);7WL =Pm.newwakelock (Powermanager.acquire_causes_wakeup8| Powermanager.screen_bright_wake_lock, "Alarmactivity");9Wl.acquire ();
View Code

For the interpretation of parameters, it is recommended to look at the official API documentation, explaining the comparative authority.

You also need to add permissions in the Manifest.xml configuration file when you use it:

1  <  android:name= "Android.permission.WAKE_LOCK"/>   <!--screen light operation Rights--
2 <  android:name= "Android.permission.DISABLE_KEYGUARD"/> <!--unlock permissions --

Resources:

Partly from the Internet. Thank you for sharing!

Introduction to Android Development-------screen light, keypad lock

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.