I've just upgraded my app to use the newly released v22.1.0 AppCompat and now onKeyDown
and onKeyUp
are not triggered when menu key is pressed. The other keys correctly trigger onKeyDown
and onKeyUp
, but when i press the menu key nothing happens. If I downgrade to v22.0.0 everything returns to work properly.
How do I fix it?
Update 23 August
This has been fixed again in the v23.0.0 of appcompat-v7 support library. Update to the last version to see this fixed.
Update 19 July
Unfortunately AppCompat v22.2.1 broke the
onKeyDown
andonKeyUp
events again. I just updatedAppCompatActivityMenuKeyInterceptor
to support v22.1.x and also v22.2.1Update 29 May
This has been fixed in the v22.2.0 of appcompat-v7 support library. Update to the last version to see this fixed.
Unfortunately AppCompat v22.1.0 intercepts the
onKeyDown
andonKeyUp
events and does not propagate them when the menu key is pressed. The only possible solution involves using Reflection to intercept theonKeyDown
andonKeyUp
events before the AppCompat does.Add this class to your project:
Call
AppCompatActivityMenuKeyInterceptor.intercept(this)
in theonCreate
of your activity:If you use ProGuard or DexGuard add these rules to your configuration:
Now your activity can receive
onKeyDown
andonKeyUp
event also for the menu key.Instead of
onKeyUp()
oronKeyDown()
, one can simply usedispatchKeyEvent()
. Look at the following code from android-developers.blogspot.com.