1,可以在InputReader.cpp中来处理,在KeyboardInputMapper类的process中来处理获取的按键,然后再调用vibrator接口。
2,参照virtual key的处理方式,可以根据Setting中的feedback使能来判断是否需要震动;文件PhoneWindowManager.java
中有接口interceptKeyBeforeDispatching,这个接口中可以根据需要来处理。
例如:
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If a system window has focus, then it doesn't make sense
// right now to interact with applications.
WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
Intent service = new Intent();
service.setClassName(mContext, "com.android.settings.SoundSettings");
ContentResolver res = mContext.getContentResolver();
if(1 == Settings.System.getInt(res, Settings.System.HAPTIC_FEEDBACK_ENABLED,0))//when setting feedback enable
{
performHapticFeedbackLw(null, HapticFeedbackConstants.KEYBOARD_TAP, true); //启动震动
}
.......................
2,参照virtual key的处理方式,可以根据Setting中的feedback使能来判断是否需要震动;文件PhoneWindowManager.java
中有接口interceptKeyBeforeDispatching,这个接口中可以根据需要来处理。
例如:
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If a system window has focus, then it doesn't make sense
// right now to interact with applications.
WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
Intent service = new Intent();
service.setClassName(mContext, "com.android.settings.SoundSettings");
ContentResolver res = mContext.getContentResolver();
if(1 == Settings.System.getInt(res, Settings.System.HAPTIC_FEEDBACK_ENABLED,0))//when setting feedback enable
{
performHapticFeedbackLw(null, HapticFeedbackConstants.KEYBOARD_TAP, true); //启动震动
}
.......................