0

The Amazon Fire Tv Stick has a dedicated menu button on it's remote that I would like to give functionality but have been unable to override. I am able to override every other button on the remote, but not the menu button. I know the menu button works because it still brings up the default Android options menu and MenuFragment. Here is my code to override the menu button.

public boolean onKeyUp (int keycode, KeyEvent event) {
    if(keycode == KeyEvent.KEYCODE_MENU) {
        Toast.makeText(this, "menu pressed", Toast.LENGTH_SHORT).show();
        return true;
    }
return super.onKeyUp(keycode, event);
}

The only reason I can think of that this might not work is if something else in my mainActivity is overriding the menu button as well, perhaps to run the options menu.

Thanks for any help!

John Gallagher
  • 525
  • 4
  • 15
  • I notice in the Amazon sample at https://developer.amazon.com/public/solutions/devices/fire-tv/docs/amazon-fire-tv-remote-input they override the onKeyDown not onKeyUp – Offbeatmammal May 14 '15 at 04:11
  • Possible duplicate: http://stackoverflow.com/questions/29852303/upgraded-to-appcompat-v22-1-0-and-now-onkeydown-and-onkeyup-are-not-triggered-wh – Daniel Nugent Aug 04 '15 at 04:07

2 Answers2

0

You might have updated the support libraries in your SDK installation and this is a known bug on Google' side, possibly overriding the behaviour for that specific button.

I believe this will be fixed with a future release of the libraries. https://code.google.com/p/android/issues/detail?id=159795

What’s the solution right now?

You could: In Gradle, open the build.gradle file and make the following modifications:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:appcompat-v7:21.0.3'
}

If the support library generates an error (squiggly red line underneath) ensure your targetSDKVersion is 19 or below.

Or https://stackoverflow.com/a/29852304/2837959

Community
  • 1
  • 1
Luca S.
  • 718
  • 7
  • 17
0

Turns out this will work in the current appcompat version.

@Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int keyCode = event.getKeyCode();
        int action = event.getAction();
        boolean isDown = action == 0;

        if (keyCode == KeyEvent.KEYCODE_MENU) {
            return isDown ? this.onKeyDown(keyCode, event) : this.onKeyUp(keyCode, event);
        }

        return super.dispatchKeyEvent(event);
    }
John Gallagher
  • 525
  • 4
  • 15