Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap cordova native android menubutton not firing

I'm having trouble firing the native menu button on Android through Cordova phonegap version 4.0.0. I have also implemented the back button and it's working fine. I'm not able to figure out what's wrong here. Seems ok according to the cordova docs. This fails when running tests on a Samsung S4.

init : function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},

onDeviceReady : function() {
// Register the event listener
document.addEventListener('backbutton', this.onBackKeyDown, false);
document.addEventListener('menubutton', this.onMenuKeyDown, false);
},

onMenuKeyDown : function(event) {
alert('menu phone home');
}

And the init function is invoked after load, and as I mentioned onBackKeyDown works. Any hints appreciated.

like image 275
Dilemmat_Dag Avatar asked Oct 19 '22 23:10

Dilemmat_Dag


1 Answers

This was supposedly fixed, but still requires an undocumented line.

document.addEventListener("deviceready", function() {
    ...
    navigator.app.overrideButton("menubutton", true);  // <-- Add this line
    document.addEventListener("menubutton", yourCallbackFunction, false);
    ...
}, false);

https://issues.apache.org/jira/browse/CB-9949#comment-14989073

like image 180
Alien Technology Avatar answered Oct 22 '22 12:10

Alien Technology