1

I developer a APP Android which can detect the type of device (smartphone normal or gamepad). I've done a test in HTC ONE M7 without the connection with a gamepad. But my code tell me that it's a gamePad.

This is my code:

InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
// Verify that the device has gamepad buttons, control sticks, or both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
{
     Log.d(TAG, "device detected : Game Pad");
}

And for HTC ONE M7's deviceID = 2, I found that the ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) is true. That's why HTC is considered as a GamePad.

Anyone knows Why ?

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
loic
  • 107
  • 1
  • 5

1 Answers1

0

I found the solution.

We should check the existence of a GamePad like this: (&& instead of ||)

InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
// Verify that the device has gamepad buttons, control sticks, or both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) && ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
{
    Log.d(TAG, "device detected : Game Pad");
}

Because for a really GamePad, it contains the InputDevice.SOURCE_GAMEPAD and InputDevice.SOURCE_JOYSTICK in the same time.

You can look this: How do I determine what is the source of Input Device in android?

Thanks.

Community
  • 1
  • 1
loic
  • 107
  • 1
  • 5