Injecting Touch events to another app on Android

HOW TO HANDLE CONTROLLER ACTION [ALSO API 16+]

At the system level, Android reports input event codes from game controllers as Android key codes and axis values. In your game, you can receive these codes and values and convert them to specific in-game actions.

When players physically connect or wirelessly pair a game controller to their Android-powered devices, the system auto-detects the controller as an input device and starts reporting its input events. Your game can receive these input events by implementing the following callback methods in your active Activity or focused View (you should implement the callbacks for either the Activity or View, but not both).

More in detail you can find in this documentation.


SUPPORT CONTROLLERS ACROSS ANDROID VERSIONS [API 12+]

If you are supporting game controllers in your game, it’s your responsibility to make sure that your game responds to controllers consistently across devices running on different versions of Android. This lets your game reach a wider audience, and your players can enjoy a seamless gameplay experience with their controllers even when they switch or upgrade their Android devices.

More in detail you can find in this documentation.


SINGLE TOUCH EVENTS

For single touch events that you want to controll you can use AccessibilityService combined with dispatchGesture. But I don’t think that is what you are really looking for. You don’t want to handle the Touch itself, but the parameters that a controller is using for. That’s why I added the 2 upper paragraphs, to achieve what you you want to have.


REASON WHY I ADDED THIS ANSWER

I know it’s kinda late but till yet there is now acceptable answer out there. And in terms of reaching higher API level, it would be useful to know how to handle these stuff. Cheers 🙂

Leave a Comment