We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1569

Summary: Android volume keys not honoured inside SDL
Product: SDL Reporter: Joseba García Echebarria <joseba.gar>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sylvain.becker
Version: HG 2.0   
Hardware: All   
OS: Android (All)   
Attachments: The same patch as shown in the bug entry
patch for documentation about forwarding volume keys on Android

Description Joseba García Echebarria 2012-08-13 07:59:27 UTC
Created attachment 924 [details]
The same patch as shown in the bug entry

The current version of SDL HG in Android doesn't do anything when volume keys are pressed.
The change makes SDL ignore volume keys so that they're handled by the OS and the sound volume can be changed within an app.

diff -r 9612bcd79130 android-project/src/org/libsdl/app/SDLActivity.java
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Sun Aug 12 23:10:16 2012 -0700
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Mon Aug 13 16:58:49 2012 +0200
@@ -544,6 +544,12 @@
     // Key events
     public boolean onKey(View  v, int keyCode, KeyEvent event) {
 
+        // Ignore volumen keys so they're handled by Android
+        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
+            keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
+			return false;
+		}
+        
         if (event.getAction() == KeyEvent.ACTION_DOWN) {
             //Log.v("SDL", "key down: " + keyCode);
             SDLActivity.onNativeKeyDown(keyCode);
Comment 1 Philipp Wiesemann 2012-11-25 03:22:53 UTC
Created attachment 994 [details]
patch for documentation about forwarding volume keys on Android

I think by default all key events should go into SDL (although not possible with some like HOME). Also the described change currently does not work if screen keyboard was shown because there are now three places were keys would have to be intercepted.

Therefore I added a different patch which changes the documentation to describe a possibility to intercept certain keys (and forward them to Android) without changing the SDLActivity.java file. The programmer then may decide if this should be enabled or not (e.g. wants to map volume keys to something else or an own volume control).
Comment 2 Sam Lantinga 2013-08-01 00:06:44 UTC
*** Bug 2002 has been marked as a duplicate of this bug. ***
Comment 3 Sam Lantinga 2013-08-01 00:19:31 UTC
After playing with some SDL Android apps, I agree this is important, and it's better to let the OS handle it by default rather than pass the volumeup/volumedown keycodes to SDL applications and make each one handle it themselves.

Applications who want to override this behavior can do so by overriding onKey() and calling the native key up/down directly.

Your patch is in, thanks!
http://hg.libsdl.org/SDL/rev/609bd82bdcf6
Comment 4 Joseba García Echebarria 2013-08-01 07:45:27 UTC
Great to know, thanks!


(In reply to comment #3)
> After playing with some SDL Android apps, I agree this is important, and
> it's better to let the OS handle it by default rather than pass the
> volumeup/volumedown keycodes to SDL applications and make each one handle it
> themselves.
> 
> Applications who want to override this behavior can do so by overriding
> onKey() and calling the native key up/down directly.
> 
> Your patch is in, thanks!
> http://hg.libsdl.org/SDL/rev/609bd82bdcf6