0

Reading USB gamepad events (button press etc.) from an application in view (focus) might not be an issue on Android. The problem is that I need these events from a persistent application/service/etc. which is not necessary in view (e.g. a foreground service). By example, when I press a certain button on the gamepad, a predefined application always should get launched, regardless of the application in view. That is, the application or process which have to receive and process the gamepad events should be persistent, specifically it never can get killed and it should keep processing the events even if loses focus.

As I understand there are neither easy nor elegant ways to do this with a physical keyboard as I have to use an accessibility service (out of question) or write my own input method (complicated and also it has its drawbacks). Maybe is there a better workaround for a gamepad? Note that the device we’re speaking about is actually a Trinket-based USB universal “button pad” which can be easily programmed to act as any HID device like gamepad, keyboard, mouse etc. Even so prefer gamepad over keyboard in order to avoid interfering with the system’s native soft keyboard (but also would be happy if I got a solution for keyboards).

Delphi Firemonkey solution would be the best but of course I’m ready to use C++, Python, Java, etc. instead if necessary. It has to work on Android 7.1 or above (at least Oreo is mandatory).

UPDATE To be a bit more clear let me show what I actually want to do. The android device in point of fact is a touch-only car head unit. I made an active frame with buttons which can act like a gamepad or physical keyboard and have the purpose to start (or switch to) media player, navigation, phone, radio etc. on the head unit (as a touch-only device can distract the driver hence is not really safe at driving time). Of course all buttons should work every time, no matter which application is currently in view.

Zoltán Bíró
  • 346
  • 1
  • 12
  • I have programmed usb serial devices on Android in Delphi using https://www.winsoft.sk/acpusb.htm libraries. They include `` in the manifest. The device filter, along with in-app permissions allows apps to gets "paired" to particular devices, so that when I plug them in, the "paired" app starts. – Freddie Bell May 13 '19 at 16:23
  • @nolaspeaker, sorry, you’ve misunderstood me. I don’t want a certain application to start when plugging in, rather to assign several applications (radio, player, navigation, phone, miracast etc.) to hardware buttons which should start every time when the respective buttons are pressed, **regardless** of the application which is actually in focus. (Normally a keystroke or gamepad action is received just by the application in view.) – Zoltán Bíró May 13 '19 at 16:49
  • I think that if you learned a little about how serial devices communicate on Android, then you will be able make an app that launches (via intent) an appropriate app for each button. Your app would probably be a background service without a visible host. You have a long road ahead of you. – Freddie Bell May 13 '19 at 17:02
  • Are you sure I need a background service? AFAIK background services can get easily killed when the android unit runs out of resources. Isn’t a foreground service a better choice here? – Zoltán Bíró May 13 '19 at 17:05
  • Yes, a foreground service would be better. – Freddie Bell May 13 '19 at 18:28
  • OK, thanks. In this case do you have already a template project or can you draw me some guidelines for making this project by myself? I’m a pretty experienced programmer in Win32/64 Delphi but quite a novice in Android (just one – say – a little more serious Android project by far). Not that big emergency if you don’t have time right now. – Zoltán Bíró May 13 '19 at 18:37
  • 1
    Your template project in this case would be the demo app that comes with the Winsoft library. – Freddie Bell May 14 '19 at 04:48

0 Answers0