Android NativeActivity - intercepting input at the Java level

允我心安 提交于 2019-12-25 08:05:52

问题


Is there a way to intercept input in a NativeActivity before it gets dispatched to the AInputQueue in native code? The reason I need to intercept input in Java is to support gamepad/joystick events that I can't capture using any of the android/input.h functions, ie. MotionEvent.getAxisValue(MotionEvent.AXIS_RZ).

This following does not work (my manifest correctly points to my derived NativeActivity class):

public class CustomNativeActivity extends NativeActivity
{
    private View.OnTouchListener touchListener = new View.OnTouchListener() {
        public boolean onTouch (View v, MotionEvent event)
        {
            // This is never called!
            System.out.println("onTouch");
            return false;
        }
    };

    public void setContentView(View view)
    {
        // This method is called, but registering a touch listener does nothing!
        view.setOnTouchListener(touchListener);
        super.setContentView(view);
    }

    public boolean dispatchTouchEvent(MotionEvent ev)
    {
        // This is never called either!
        System.out.println("dispatchTouchEvent!");
        return super.dispatchTouchEvent(ev);
    }
}

来源:https://stackoverflow.com/questions/8920454/android-nativeactivity-intercepting-input-at-the-java-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!