Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Created November 6, 2011 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbuehlmann/1342725 to your computer and use it in GitHub Desktop.
Save tbuehlmann/1342725 to your computer and use it in GitHub Desktop.
Android Media volume and speakers issue
Using an HTC Desire (Android 2.2 Froyo), I experienced two weird problems at some time.
1. When listening to music with the default player (didn't try others), I wasn't able to adjust the media volume. The media volume bar moved but the volume actually didn't change. This happened only when earphones/headphones were plugged in.
2. When having a phone call, the phone automagically switched to using the phone speakers. I had to manually switch the speakers off. Each time.
These problems appeared suddenly and were permanent.
I familiarized with the problems since I wasn't able to find a solution. I read about some solutions regarding resetting the phone completely and switching it "off and on again" (seriously…). Tried switching it off and on again, no changes. Didn't try resetting it.
Then I startet to program with JRuby (http://jruby.org/) via SL4A (http://code.google.com/p/android-scripting/) on my phone and executed some scripts to just see how things work with JRuby. The one important snippet I ran was "toggle_airplane.rb" (see other file in this Gist). This happened just for test purposes, I had no idea this would solve my problem. When the next call arrived my phone, I took it and wondered why the phone speakers were off. Well, whatever, this might be just temporarily. But I also checked the music player with earphones plugged in and the media volume was adjustable just as normal.
So I accidentally repaired my HTC Desire. This might work without JRuby, just using a simple Java snippet including the correct API calls.
# Toggle airplane mode twice to fix stuck GPS/network...
droid = Android.new
droid.toggleAirplaneMode
droid.toggleAirplaneMode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment