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 ();}}......}