Thanks! I had seen that before but didn’t realise that I could actually edit the Cordova platform code. A quick file search in the platforms
directory proved otherwise. It still seems wrong to be changing cordova’s java code, but I guess that’s why it’s called a monkey patch.
I edited the method onDispatchKeyEvent
in file platforms/android/CordovaLib/src/org/apache/cordova/CordovaWebViewImpl.java
on line 549 and commented out the boundKeyCodes
check as per below.
@Override
public Boolean onDispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
boolean isBackButton = keyCode == KeyEvent.KEYCODE_BACK;
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isBackButton && mCustomView != null) {
return true;
} else if (boundKeyCodes.contains(keyCode)) {
return true;
} else if (isBackButton) {
return engine.canGoBack();
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
if (isBackButton && mCustomView != null) {
hideCustomView();
return true;
} else { //if (boundKeyCodes.contains(keyCode)) {
String eventName = null;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
eventName = "volumedownbutton";
break;
case KeyEvent.KEYCODE_VOLUME_UP:
eventName = "volumeupbutton";
break;
case KeyEvent.KEYCODE_SEARCH:
eventName = "searchbutton";
break;
case KeyEvent.KEYCODE_MENU:
eventName = "menubutton";
break;
case KeyEvent.KEYCODE_BACK:
eventName = "backbutton";
break;
}
if (eventName != null) {
sendJavascriptEvent(eventName);
return true;
}
}
// else if (isBackButton) {
// return engine.goBack();
// }
}
return null;
}
Also here’s the Cordova issue opened about this for reference: https://issues.apache.org/jira/browse/CB-8921