Xposed - 长按检测键(可以检测正常按,但不能长按)

时间:2016-02-03 07:23:17

标签: android xposed

我正在尝试按键长按,我正在收听的键是音量调高/音量调低/返回键,使用Xposed我已经挂上了一个类并设法听取它们,只有2个问题:

我在按下音量增加时添加了一个logcat,问题是我得到了7次日志,即使我只按了一次。

我无法听长按,isLongPressed无效。

以下是代码:

 public static void init() {

    final Class localClass = XposedHelpers.findClass("com.android.internal.policy.impl.PhoneWindowManager", Xposed.CLASS_LOADER);
    XposedBridge.hookAllConstructors(localClass, new XC_MethodHook() {
        protected void afterHookedMethod(final XC_MethodHook.MethodHookParam paramAnonymousMethodHookParam)
                throws Throwable {
        }
    });

    XposedHelpers.findAndHookMethod(localClass, "interceptKeyBeforeQueueing", KeyEvent.class, Integer.TYPE, new XC_MethodHook() {
@Override
        protected void beforeHookedMethod(MethodHookParam param)
                throws Throwable {
            KeyEvent event = (KeyEvent) param.args[0];
            int code = event.getKeyCode();

            if (code == KeyEvent.KEYCODE_BACK) {
                Log.i(Xposed.TAG, "Back Pressed");
            }
        }
    });

0 个答案:

没有答案