I want to catch events from keys and motion events from joystick connected to my Android.
I'm using InputManager.InputDeviceListener
but the minimal API level supported is 14 and InputManager.InputDeviceListener
requires API level 16.
Do you know a solution supported by API level 14 ?
Code that not compiling :
public class MyActivity extends Activity implements InputManager.InputDeviceListener {
@Override
public void onResume() {
inputManager.registerInputDeviceListener(this, null);
// Query all input devices.
// We do this so that we can see them in the log as they are enumerated.
int[] ids = inputManager.getInputDeviceIds();
for (int i = 0; i < ids.length; i++)
{
getInputDeviceState(ids[i]);
}
}
@Override
protected void onPause()
{
inputManager.unregisterInputDeviceListener(this);
}
public InputDeviceState getInputDeviceState(int deviceId)
{
InputDeviceState state = inputDeviceStates.get(deviceId);
if (state == null)
{
final InputDevice device = inputManager.getInputDevice(deviceId);
if (device == null)
{
return null;
}
state = new InputDeviceState(device);
inputDeviceStates.put(deviceId, state);
}
return state;
}
}
Code is from Android samples.