标签:android style ar java sp for div on bs
实现思路:
WindowManagerService循环读取下面按键消息并分发给窗口,在消息分发前会在PhoneWindowManager.interceptKeyBeforeQueueing方法中进行消息的过滤。因此该实现方式为在消息分发前的interceptKeyBeforeQueueing方法中监听当前按键为音量下键,如果当前状态为锁屏状态,并按键为音量下键,且两次按键间隔时间小于800ms时发送抓拍广播--"com.bill.snapshot"。
具体实现方式如下:
/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();
}
}
......
}
Android锁屏或灭屏状态下,快速按两次音量下键实现抓拍功能(一,Framework层实现)
标签:android style ar java sp for div on bs
原文地址:http://blog.csdn.net/huangyabin001/article/details/41008593