I have an android application that is meant to be used with a game controller connected to the android device.
Most game controllers have a center 'home' button that I would like to use to pause the game (for example, an Xbox controller center nexus button should pause).
However, when you press the center nexus button on the controller it causes the entire app to close as though the actual home button on the phone was pressed. Why is the center button on some controllers causing the app to return to the home screen? Note, this doesn't happen with all controllers or all devices. For example, using a pixel 6 and an xbox controller it doesn't send the app home. But using a galaxy a32 the center nexus button does triggers the home action.
I understand its not possible to intercept the actual home action from within an app. But is it possible to do so from a physical controller? Or is it possible to remap the controller buttons?
I tried this in an attempt to intercept the home action:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.e("KeyPress", "Code: " + keyCode);
switch (event.getKeyCode()){
case KeyEvent.KEYCODE_HOME:
return false;
default:
return super.onKeyDown(keyCode, event);
}
}
but this isn't working. Pressing the center button on the controller doesn't trigger the log but it still goes to the home screen.
Any ideas how to make certain button on physical controllers not trigger the home action?
Thanks