Android NativeActivity – 拦截Java级别的输入

有没有办法在NativeActivity中将输入拦截到本机代码中的AInputQueue之前? 我需要在Java中拦截输入的原因是支持我无法使用任何android/input.h函数捕获的游戏手柄/操纵杆事件,即。 MotionEvent.getAxisValue(MotionEvent.AXIS_RZ)

以下内容不起作用(我的清单正确指向我派生的NativeActivity类):

 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); } }