As we have analyzed in the previous post, we can use the broadcast format to make a broadcast when the two volume keys are pressed quickly to facilitate the client to capture. Since there are two ways to implement the issue, which is the preferred way? I personally recommend the use of the start-up service, so that you can avoid multiple consecutive keystrokes resulting in repeated broadcasts, while using the service will not restart the service repeatedly.
The specific implementation is as follows:
/framework/base/policy/src/com/android/policy/impl/phonewindowmanager.java
Private long lasttime=0;
public int interceptkeybeforequeueing (keyevent event,int Policyflags,boolean isscreenon) {if (Event.getkeycode () ==Key Event.keycode_volume_down && Event.isdwon ()) {if (iskeyguardlocked ()) {if (system.currenttime Millis ()-lasttime) < () {Intent intent=new Intent (); ComponentName component=new componentname ("Com.xxx.xxx", "Com.xxx.xxx.SnapshotService");
Intent.setcomponent (component);
Mcontext.startservice (Intent); } lasttime=system.currenttimemillis (); } }......}
Android lock screen or off-screen state, quickly press two times the volume key to achieve snapshot function (1.2Framework layer using StartService form)