androidc++inputandroid-ndkmotorola

Android NDK Input Sources


I have a native C++ Android application.

I am using the AINPUT_SOURCE enums to filter through input events as they come into my native activity. For now, I only care about AINPUT_SOURCE_TOUCHSCREEN (0x1002).

This seems to work on 99% of devices, however the Motorola Moto G6 Plus does not comply to this standard.

The G6 reports the input source as 0x5002. No matter how many times you tap the touch screen, the device will never send an actual touch screen input event.

I only was able to discover this by buying one myself, after months of G6 users reporting not being able to play my game.

The official Android NDK reference site doesn't even have an input source listed with the value (0x5002).

I have looked around and there doesn't seem to be any discussions on the issue.

Are there any other AINPUT_SOURCE types that I should know about? Ones that aren't listed on the NDK reference.

I would like to be able to continue to use these flags to keep my touch input code separated from keyboard, mouse, controller buttons, etc.

Thanks!

Android NDK input reference:

https://developer.android.com/ndk/reference/group/input


Solution

  • These are ENUMs so you have to calculate them in this way: 5002 is made of 0x02 + 0x1000 + 0x4000 = touchscreen + stylus + button. It seems that device has a stylus and a button, so you will get Events for all these THREE things. To check if the device supports the TOUCHSCREEN you just have to perform "founded_flag & 0x1000 == 0x1000" and if this check gives you a TRUE value then that device supports the common touscreen behavior.