我开发了一个可以检测设备类型(智能手机普通或游戏手柄)的 APP Android。我在 HTC ONE M7 中做了一个没有连接游戏手柄的测试。但我的代码告诉我这是一个游戏手柄。
这是我的代码:
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");
}
而对于 HTC ONE M7 的 deviceID = 2,我发现 ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) 为真。这就是 HTC 被视为 GamePad 的原因。
有谁知道为什么?