有没有办法在 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);
}
}