Michael B
Michael B

Reputation: 1719

Cordova - menubutton-event doesn't fire

I am developing an Android-Application with cordova. The android 4.4 device is connected with a bluetooth remote control.

With the help of the documentation, I am able to catch some buttons, e.g. the "volume-up"-key:

document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);

function onVolumeUpKeyDown() {
    console.log("Volume up pressed");
}

According to the cordova-documentation, there are some other Eventlisteners for keys available:

I want that the user gets to the settings-page of my application, when he presses the remotes menu-button, but Unfortunately this button doesn't work for me. Here is the description on the cordova site and the sample code:

document.addEventListener("menubutton", onMenuKeyDown, false);

function onMenuKeyDown() {
  console.log("Menu pressed");
}

I have found an APK named "keytest", which shows the pressed keys. This app recognizes:

keyCode=KEYCODE_MENU

still, cordova doesn't fire the event... Why?

Screenshot Keytest

Upvotes: 3

Views: 883

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

It's not documented, but you have to override the menu button to make it work

add this line

navigator.app.overrideButton("menubutton", true);

Then you can use

document.addEventListener("menubutton", yourCallbackFunction, false);

Upvotes: 10

Related Questions