Hmmmm ... onLongKeyPress()
doesn't seem to work with KEYCODE_MENU
. How annoying.
This is similar to working with Nexus S (4.0.3) and Nexus One (2.3.6):
public class MenuKeyDetectorActivity extends Activity { boolean wasLongPress=false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { wasLongPress=wasLongPress | event.isLongPress(); } return(false); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { Log.w("MKD", String.format("wasLongPress: %b", wasLongPress)); wasLongPress=false; } return(false); } }
Basically, note that this is a long press or not in your onKeyDown()
calls, then use this information in onKeyUp()
to determine the final location.
source share