0

I want to prevent users from being able to take a picture with the external camera button on Google Glass when inside my app.

I am currently catching any camera button events in my main Activity by overriding the "onKeyDown" method. However, I found that if a Google Glass option menu is opened within my app when the user needs to select a menu item (e.g. when method "openOptionsMenu" is invoked), the keyEvents are handled separately from my activity, and users can end up accidentally taking a picture.

Is there a way to capture keyDown events when within the options panel?

Is there a way to get access to the "view" that holds the option panel, and add an onKey listener to it? I have looked into trying to obtain this view via "onCreatePanelView", but that method just returns null.

An alternative is for me to override onCreatePanelView and create my own custom panel view, but I am hoping for a solution that avoids this and allows me to add an onKeyDown listener to the default option panel.

1 Answers1

0

You may try using this code snippet while in a menu:

    public boolean onKeyDown(int i, KeyEvent keyevent) {
        if (i == 27) {
            keyevent.startTracking();
            return true;
        }
        else {
            return super.onKeyDown(i, keyevent);
        }
    }
rAntonioH
  • 129
  • 2
  • 12
  • Thanks for the suggestion. I have onKeyDown overridden in my main activity, and it catches the camera button fine outside of the options menu. However, when the options menu is opened, the Window creates a panel view that seems to be independent of the current activity. Hence, onKeyDown is not invoked when this panel view is open. – andrewl1030 Jul 29 '14 at 01:59