5,596,431 Members 40,074 Now Online
XDA Developers Android and Mobile Development Forum

How to make headset button control music on the stock ROM

Tip us?
Junior Member - OP
Thanks Meter 4
Posts: 6
Join Date: Sep 2012
Audio How to make headset button control music on the stock ROM

I'm not sure this is the right subforum for this, but I was coming here to ask how to do this before I figured it out for myself. So I figured I should post about it in case I forget what I did.

I just switched to a shiny new G2, and I'm using the one-button earphones that came with my Nexus S 4G. This is actually the third set of such headphones (I keep breaking and replacing them), so I refuse to have them not work on my rooted but otherwise stock G2.

When I first plugged them in to the G2, it was configured so that the button would control the phone function: one press would open my call history, a double press would redial, and a hold would start up voice dialer. On the Nexus S 4G, the buttons controlled my media player, so that's what I want them to do here.

I tried various button remapping tools like the JAYS Headset Control app, but none of them would take precedence over the default LG actions.

Instead, I modified this approach from the Nexus 4, and changed the key code for the button from the one that the voice dialer controls were intercepting (HEADSETHOOK) to something else (MEDIA_NEXT).

What I did:

1. Have root and install Busybox (for vi).

2. Get a root shell on the device.

$ adb shell
shell@android:/ $ su
root@android:/ #
3. Mount /system as read-write:

root@android:/ # mount -o rw,remount /system
4. Edit the default Android keyboard layout to swap the HEADSETHOOK and MEDIA_NEXT keys.

root@android:/ # vi /system/usr/keylayout/Generic.kl
Press "i" to enter insert mode. Move around with the arrow keys.


key 163   MEDIA_NEXT

And also change:


key 226   MEDIA_NEXT
Press Escape, and then press Shift + Z twice to save and quit.

5. Reboot your device for the changes to take effect.

6. Now the button on your single-button headset is the equivalent of the "down" or "next" button on a three-button headset. To configure it, install JAYS Headset Control or a similar application. Chose the three-button headset instead of the one-button headset, and configure the third button to do everything you want your button to do.

7. Enjoy your customizable button!
The Following 3 Users Say Thank You to interfect For This Useful Post: [ Click to Expand ]
Myzur's Avatar
Thanks Meter 1
Posts: 34
Join Date: Jun 2007
Sweet! Not having my headset button work for audio was my biggest issue with the G2.

I followed the instructions above, but instead of swapping "key 163 MEDIA_NEXT" I swapped "key 164 MEDIA_PLAY_PAUSE". This caused the default behavior to be "Play/Pause".

I tried using JAYS Headset Control and it works great. Thanks for the find!
Thanks Meter 23
Posts: 71
Join Date: Jun 2013
Oh my gosh! I've been looking everywhere for this solution. Thank you so much!

My dilemma was that I want to be able to use the headset buttons because I listen to music and switch tracks frequently while walking around the university. Only the Android KitKat ROMs worked for me, but the problem with those ROMs is that GPS has locking problems and/or doesn't work at all.
Junior Member
Thanks Meter 0
Posts: 19
Join Date: Dec 2012
Location: Atlanta, GA
Thanks for this, it was helpful for me also. Like Myzur I've also used MEDIA_PLAY_PAUSE instead of MEDIA_NEXT.

I had a quick go with the "Headset Button ControllerTrial" app for some extended functionality, but it kept switching from Rhapsody to LG's music app. This was before I saw the comment about configuring things as if it were a 3 button headset, so I'll play around with this some more (and will probably also try the JAYS app). But even as-is, just the ability to play/pause is a very nice improvement over stock behavior (honestly, who uses their phone more for making calls than listening to music.. ).
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes