I found the solution, very obvious, but somehow I was always just
looking at onKeyUp, instead of onKeyDown.
Overriding onKeyDown works fine.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            return true;
        } else return super.onKeyDown(keyCode, event);
    }



On Jul 27, 11:46 pm, Mathias Lin <m...@mathiaslin.com> wrote:
> Thanks for your reply. Not sure though what you mean with
> compatibility reasons - in fact all phones handle it differently
> anyways? Why wouldn't it be wise to allow developers to disable it? I
> didn't fully get the idea.
>
> About disabling such functions: there are situations where it makes
> sense to disable it. In my case I bundle an app with a device that I'm
> giving to the users. So only my app runs on the device anyway, it
> starts at boot-time, and I'm in control of the devices (just renting
> it out to users); still I don't want to root it or modify the core in
> any way due to guarantee reasons.
> In my case, I've put specific features on the menu button and the
> other soft buttons, but I don't want the default behaviour to appear
> on long press; I'd like to override it with the same app-specific
> behaviour that I use for a short press on this button (which I can
> capture via onKeyUp for example).
>
> Actually I would like to get the behaviour as it is on my G1 (1.6):
> which is that long press is the same as short press. There's no
> difference between long press and short press. Not sure if it's due to
> 1.6 version on it, but I think so.
>
> But on my Nexus One (2.2) it's different (showing the soft keyboard)
> and on the Samsung Galaxy S (2.1) as well. Doesn't make much sense to
> me to have a search widget hidden behind the menu button on long
> press.
>
> I understand that the home button shouldn't be able to be overriden in
> order not to trap users in your app; but why shouldn't the developer
> be able to handle the menu button/long press?
>
> On Jul 27, 10:34 pm, Joseph Earl <joseph.w.e...@gmail.com> wrote:
>
>
>
> > I don't think you can.
> > Pressing and holding the menu button to show the soft keyboard exists
> > for compatibility reasons - I'm not sure it would be wise to allow
> > developers to disable it.
>
> > On Jul 27, 12:18 pm, Mathias Lin <m...@mathiaslin.com> wrote:
>
> > > How can I capture a long press of the device menu button in my 
> > > application?
> > > I thought of an intent filter, but there's only an action called
> > > android.intent.action.SEARCH_LONG_PRESS, but nothing for the MENU button.
>
> > > I found that long press of the menu button actually does different
> > > things on different devices, i.e. on Nexus One it will show the soft
> > > keyboard, while on Samsung Galaxy S it will pop up the search widget.
> > > Generally, I want to suppress this behaviour in my app.
>
> > > (I already looked on StackOverflow.com for some hints but only found
> > > unanswered posts.)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to