当时这个需求是,连续点击camera键启动扫码app。由于怕和其他app共享一个广播,所以自己定义了一个广播
ACTION_CAMERA_BUTTON.DC
扫码app监听ACTION_CAMERA_BUTTON.DC这个广播。
修改文件
frameworks/base/policy/src/com/android/internal/policy/impl/PhoneFallbackEventHandler.java
boolean onKeyDown(int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_CAMERA: {
//start
if(event.getRepeatCount() == 5){
Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON+"DC", null);
intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
null, null, null, 0, null, null);
}
//end
else if (event.isLongPress() && dispatcher.isTracking(event)) {
dispatcher.performedLongPress(event);
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
sendCloseSystemWindows();
// Broadcast an intent that the Camera button was longpressed
Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
null, null, null, 0, null, null);
}
}
如果点击次数等于5次就发起广播给扫码app