As far as I know, this is not possible.
As you said in the comments, you can do this if your application is running in native mode (the native-activity example shows how to start from it). In the end, you'll probably have something like:
int32_t handle_input(struct android_app* app, AInputEvent* event) {
int32_t eventType = AInputEvent_getType(event);
switch(eventType){
case AINPUT_EVENT_TYPE_MOTION:
switch(AInputEvent_getSource(event)){
case AINPUT_SOURCE_TOUCHSCREEN:
int action = AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK;
switch(action){
case AMOTION_EVENT_ACTION_DOWN:
break;
case AMOTION_EVENT_ACTION_UP:
break;
case AMOTION_EVENT_ACTION_MOVE:
break;
}
break;
}
break;
case AINPUT_EVENT_TYPE_KEY:
break;
}
}
If I'm not mistaken, you cannot handle input in your own code if your application runs in standard Java activity.
source
share