How to handle touchscreen events in Android source code without going through Java *?

We would like to handle all touch inputs using native Android code. We want to initialize the code from the Android onCreate () method, and then take over all the inputs. We examined our own activity in the sample, however, we believe that some structures and methods that it uses are available only for all applications.

After initialization, it should work on its own, handling touch events. He will move on to the Java methods that we have already figured out. The problem that we are facing does not allow Java to process methods, and how to get the native code to process touch inputs without calling it and the event has passed.

How can we configure this native code to handle all touch events without having to go through an Activity.onTouchEvent (MotionEvent event)?

+4
source share
2 answers

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;
            } // end switch
        break;
        case AINPUT_EVENT_TYPE_KEY:
            // handle key input...
        break;
    } // end switch
}

If I'm not mistaken, you cannot handle input in your own code if your application runs in standard Java activity.

+3
source

java. - SDK.jar Android. .

+1

Source: https://habr.com/ru/post/1526485/


All Articles