Android lock screen or off-screen state, quickly press two volume down key to achieve snapshot function (one, the framework layer implementation)

Source: Internet
Author: User

Implementation ideas:The Windowmanagerservice Loop reads the following key messages and distributes them to the window, filtering the messages in the Phonewindowmanager.interceptkeybeforequeueing method before the message is distributed. Therefore, the implementation of the message before the distribution of the Interceptkeybeforequeueing method to listen to the current key is the volume down key, if the current state is the lock screen state, and the key is the volume down key, and two times the key interval less than 800ms to send snapshot broadcast-" Com.bill.snapshot ".
The specific implementation is as follows:
/framework/base/policy/src/com/android/policy/impl/phonewindowmanager.java
Private long lasttime=0;private Keyguard mkeyguardmanager;private keyguard Getkeyguardmanager () {if (mKeyguardManager=    =null) {mkeyguardmanager= (Keyguradmanager) Mcontext.getsystemservice (Context.keyguard_service); } return Mkeyguradmanager;}

public int interceptkeybeforequeueing (keyevent event,int Policyflags,boolean isscreenon) {if (Event.getkeycode () ==Key              Event.keycode_volume_down && Event.isdwon ()) {if (Getkeyguardmanager (). Inkeyguardrestrictedinputmode ()) { if ((System.currenttimemillis ()-lasttime) <) {Intent intent=new Intent ("Com.bill.snapsh                  OT ");             Mcontext.sendbroadcast (Intent);          } lasttime=system.currenttimemillis (); }      }......}

Android lock screen or off-screen state, quickly press two volume down key to achieve snapshot function (one, the framework layer implementation)

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.