问题
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