[ https://issues.apache.org/jira/browse/CB-12347?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Anatoly Shirokov updated CB-12347: ---------------------------------- Affects Version/s: Master > [cordova-android] menubutton and searchbutton events are not fired > ------------------------------------------------------------------- > > Key: CB-12347 > URL: https://issues.apache.org/jira/browse/CB-12347 > Project: Apache Cordova > Issue Type: Bug > Components: Android, CordovaJS > Affects Versions: Master > Environment: android > Reporter: Anatoly Shirokov > Priority: Critical > Labels: patch > > 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() { > exec(null, null, APP_PLUGIN_NAME, "overrideButton", > [buttonName, this.numHandlers == 1]); > }; > } > // 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() { > exec(null, null, APP_PLUGIN_NAME, "overrideButton", > [buttonName, this.numHandlers == 1]); > }; > } > // 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 -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org