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
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 HEADSETHOOK
And also change:
key 226 HEADSETHOOK
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!