cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sven Casimir (JIRA)" <>
Subject [jira] [Commented] (CB-8921) menubutton event not firing
Date Fri, 06 Nov 2015 11:03:27 GMT


Sven Casimir commented on CB-8921:

Tried several patches, the common suggestion to disable the boundKeyCodes check didn't do
it for me, because then the backbutton behaviour would be compromised.
So I dug deeper into the code and found a way to make the menubutton work again. 
The boundKeyCodes check ensures, that custom behaviour is only executed when there actually
is a custom event handler. But binding an event handler to "menubutton" in your app's JS code
no longer triggers the menubutton key code to be added to the boundKeyCodes list. You can
get that behaviour back by doing the following changes:

in platform_www/cordova.js in the bootstrap function (around line 1532) change this line:
to this:
var menuButtonChannel = cordova.addDocumentEventHandler('menubutton');
menuButtonChannel.onHasSubscribersChange = function() {
  exec(null, null, APP_PLUGIN_NAME, "overrideButton", ['menubutton', this.numHandlers == 1]);

This will trigger the frameworks overrideButton method as soon as an event handler is added
to "menubutton".
Then change the overrideButton method in CordovaLib/src/org/apache/cordova/
line 243 make the method look like this (add the last else-if clause):
    public void overrideButton(String button, boolean override) {
        LOG.i("App", "WARNING: Volume Button Default Behavior will be overridden.  The volume
event will be fired!");
        if (button.equals("volumeup")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_VOLUME_UP, override);
        else if (button.equals("volumedown")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_VOLUME_DOWN, override);
        else if (button.equals("menubutton")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_MENU, override);

Finally in CordovaLib/src/org/apache/cordova/ line 357 (setButtonPlumbedToJs)
add a case statement after the KEYCODE_MENU entry like this:
public void setButtonPlumbedToJs(int keyCode, boolean override) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_MENU:
                // TODO: Why are search and menu buttons handled separately?
                if (override) {
                } else {
                throw new IllegalArgumentException("Unsupported keycode: " + keyCode);

That should do it. At the moment I don't exactly know to which repository I should contribute,
if anyone could give me a little hint to the appropriate github repo, I will file a pull request
for this.

> menubutton event not firing
> ---------------------------
>                 Key: CB-8921
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>         Environment: Android Emulator, SDK 19
>            Reporter: Jean-Luc Desroches
>            Assignee: Joe Bowser
>            Priority: Minor
> After updating to latest version of cordova (5.0) menubutton event is never triggered.
Have tested in hello world app, as well as in my  own app, neither of which register any menubutton

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message