Android bright screen lock and keyboard lock

Source: Internet
Author: User

Two locks in Android-unlock lock and keyguardlock for detailed analysis [Copy link]
Unlock lock-wake up lock for screen Lighting
Keyguardlock-as the name implies, the keyboard lock is used to unlock the keyboard.

Details:
1: unlock lock wake-up lock
-Can unlock lock really light the screen?
The answer is yes. However, sometimes the screen is not lit. This is a problem with parameter settings.
Powermanager. newwakelock (powermanager. full_wake_lock | powermanager. acquire_causes_wakeup, "Gank ");
Powermanager. full_wake_lock this parameter is the degree to which the phone is lit (what CPU, screen brightness, keyboard light)
The key to powermanager. acquire_causes_wakeup is the understanding of this parameter.
Screen lock does not actually light up the screen. You can understand that it lights up the screen through the android component (activity.
If a notification wants to light up the screen, the question is, can it light up? Certainly not.
However, with this powermanager. acquire_causes_wakeu parameter, you can light up the screen. It enables unlock lock to light up the screen without relying on components.

-How does unlock lock obtain the screen status?
Powermanager. isscreenon () method; this method returns true: the screen is awake, and false: the screen is sleep.

-How does the unlock lock wake up and sleep process?
Unlock lock. aquire () wakes up the screen while the screen is sleeping
Unlock lock. Release () enables the screen to sleep when the screen is lit.
The unlock lock. Release () method has a note:
For example, the unlock Locka object first wakes up the screen and then sleep the screen. OK is OK.
The screen itself is the wake-up status. The volume Locka object has not woken up the screen, and the volume Locka object tries to sleep the screen. An unlock sreen exception occurs.
2: keyguardlock
-Does keyguardlock unlock the current screen?
Keygroundmanager. inkeyguardrestrictedinputmode (): True indicates that the keyboard is locked; false indicates that the keyboard is unlocked.

-How does keyguardlock unlock and lock the screen?
Keyguardlock. disablekeyguard () unlock the keyboard
Keyguardlock. reenablekeyguard () Lock the keyboard

Keyguardlock does not have the above wake-up lock problem. No matter whether your keyboard is unlocked by keyguardlocka or not, the reenablekeyguard () method of the keyguardlocka object will not be abnormal.

These two locks have some conceptual understanding. If you think you have obtained a keyboard Lock Object, you can lock the screen. This is a big mistake.
You can't lock the screen opened by other programs (if you can, A for loop keeps locking your screen, and you have no tears to cry)

You can control your own locks instead of others' locks.

Summary:
These two locks are usually used together. You certainly do not want the screen to be dark when unlocking the screen. When you disable the keyboard lock, you want the screen to sleep at the same time.

Problem:
1: I tried to manually close the screen, but it was always so small.
2: If the screen is automatically disabled by the mobile phone, the problem does not occur.

 

Main Code display:

Keyguardmanager = (keyguardmanager) This. getsystemservice (context. keyguard_service); </P> <p> keyguardlock = keyguardmanager. newkeyguardlock ("whatever you want to write"); </P> <p> keyguardlock. disablekeyguard (); <br/> 

 

/** <Br/> * Light up the screen <br/> */<br/> private void lightscreen () {<br/> powermanager = (powermanager) This. getsystemservice (context. power_service); <br/> wakelock = powermanager. newwakelock (powermanager. full_wake_lock | powermanager. acquire_causes_wakeup, ""); <br/> wakelock. acquire (); <br/>} 
Note: Android. Permission. disable_keyguard is required for unlocking.
 

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.