Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
Master
-
None
-
android
Description
I have ionic 2 project. I try to add event handler to the menubutton event:
document.addEventListener("menubutton", this.onMenuButtonPress, false);
But when I run my application on Android device and press menu button, my handler is never called.
I investigated https://github.com/apache/cordova-android/blob/master/cordova-js-src/platform.js and found, that menubutton and searchbutton are not overrided in opposite to volumeup, volumedown:
// Add hardware MENU and SEARCH button handlers
cordova.addDocumentEventHandler('menubutton');
cordova.addDocumentEventHandler('searchbutton');
function bindButtonChannel(buttonName) {
// generic button bind used for volumeup/volumedown buttons
var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
volumeButtonChannel.onHasSubscribersChange = function()
}
// Inject a listener for the volume buttons on the document.
bindButtonChannel('volumeup');
bindButtonChannel('volumedown');
To fix issue I have patched the platform.js:
function bindButtonChannelWithoutSuffix(buttonName) {
// generic button bind used for volumeup/volumedown buttons
var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName);
volumeButtonChannel.onHasSubscribersChange = function() { exec(null, null, APP_PLUGIN_NAME, "overrideButton", [buttonName, this.numHandlers == 1]); }
;
}
// Add hardware MENU and SEARCH button handlers
bindButtonChannelWithoutSuffix('menubutton');
bindButtonChannelWithoutSuffix('searchbutton');
function bindButtonChannel(buttonName) {
// generic button bind used for volumeup/volumedown buttons
var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
volumeButtonChannel.onHasSubscribersChange = function()
;
}
// Inject a listener for the volume buttons on the document.
bindButtonChannel('volumeup');
bindButtonChannel('volumedown');
Hope it will be enough to fix this issue.
Thanks in advance!
BR,
Anatoly Shirokov