Android Question Want to absorb Activity_KeyPress KeyCodes.KEYCODE_BACK but Pass-through Volume Up and Down

TheWind777

Active Member
Licensed User
Longtime User
I am intercepting the KEYCODE_BACK button... but when I do a "return TRUE" to absorb the event, that disables the volume control UI.

How do I "return TRUE" from
Activity_KeyPress()
to absorb the KEYCODE_BACK, yet pass
KeyCodes.KEYCODE_VOLUME_DOWN and
KeyCodes.KEYCODE_VOLUME_UP events on so the Volume Control UI pops-up and handles them?

Ah... never mind. Too simple.

All I have to do is go:

B4X:
Sub Activity_KeyPress(KeyCode AsInt) AsBoolean'Return True to consume the event
Dim ReturnValue as Boolean

If KeyCode = KeyCodes.KEYCODE_VOLUME_UP or KeyCodes.KEYCODE_VOLUME_DOWN then
    ReturnValue = False
else If KeyCode = KeyCodes.KEYCODE_BACK Then
     ' Handle KeyCodes
    ReturnValue = True
end if
Return ReturnValue
end sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…