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); //启动震动
}
.......................
实现按键震动反馈
本文介绍如何在InputReader.cpp中处理按键事件并实现震动反馈。通过KeyboardInputMapper类的process方法获取按键,并根据设置中的反馈使能来判断是否需要触发震动。

被折叠的 条评论
为什么被折叠?



