In the Android lock screen or off-screen status, you can quickly press the volume down key twice to implement the capture function (1, implemented at the Framework layer) and android lock screen

Source: Internet
Author: User

In the Android lock screen or off-screen status, you can quickly press the volume down key twice to implement the capture function (1, implemented at the Framework layer) and android lock screen
Implementation idea: WindowManagerService cyclically reads the following key messages and delivers them to the window. messages are filtered in the PhoneWindowManager. interceptKeyBeforeQueueing method before message distribution. Therefore, this method is used to listen to the current button as the volume down key in the interceptKeyBeforeQueueing method before message distribution. If the current status is locked, press the button as the volume down key, when the interval between two buttons is less than ms, a screenshot broadcast is sent -- "com. bill. snapshot ".
The specific implementation method 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 () = KeyEvent. KEYCODE_VOLUME_DOWN & event. isDwon () {if (getKeyguardManager (). inKeyguardRestrictedInputMode () {if (System. currentTimeMillis ()-lastTime) <800) {Intent intent = new Intent ("com. bill. snapshot "); mContext. sendBroadcast (intent);} lastTime = System. currentTimeMillis ();}}......}

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.