Post Reply

Audio How to make headset button control music on the stock ROM

OP interfect

26th December 2013, 07:26 AM   |  #1  
OP Junior Member
Thanks Meter: 4
 
6 posts
Join Date:Joined: Sep 2012
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.

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

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

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

Change:

Code:
key 163   MEDIA_NEXT
to:

Code:
key 163   HEADSETHOOK
And also change:

Code:
key 226   HEADSETHOOK
to:

Code:
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: [ View ]
26th December 2013, 05:41 PM   |  #2  
Myzur's Avatar
Member
Thanks Meter: 6
 
44 posts
Join Date:Joined: Jun 2007
Thumbs up
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!
19th January 2014, 05:18 PM   |  #3  
Member
Thanks Meter: 26
 
71 posts
Join Date:Joined: 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.
20th January 2014, 03:25 PM   |  #4  
Member
Flag Atlanta, GA
Thanks Meter: 11
 
45 posts
Join Date:Joined: Dec 2012
More
Thumbs up
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.. ).
3rd July 2014, 05:39 PM   |  #5  
Junior Member
Flag Bronx
Thanks Meter: 1
 
15 posts
Join Date:Joined: Aug 2012
doesnt work
For some reason this doesnt work with the LG G2 Sprint version, is there any other solution?
3rd July 2014, 06:21 PM   |  #6  
Member
Flag Atlanta, GA
Thanks Meter: 11
 
45 posts
Join Date:Joined: Dec 2012
More
Quote:
Originally Posted by pabel101

For some reason this doesnt work with the LG G2 Sprint version, is there any other solution?

My phone is LG G2 on Sprint (LS980), and it actually does work for me.

Since my above post, I have actually changed the mapping again to MEDIA_NEXT, and I'm using the Headset Button Controller app (https://play.google.com/store/apps/d....headsetbutton). The actions in the controller app are all set under "Right button actions" (so exactly according to step 6 in the OP..).

I think any app that will let you configure things for a 3rd/right button should work. The JAYS one is free, but as I recall it asked for a permission I wasn't comfortable with, and I ended up with Kober's app instead, which I think was $2 and to me well worth it (you can barely get a coffee for that these days..). There is a free trial.

This setup works great for music controls (play/pause, next/previous, volume control), but it doesn't seem call control (answer/hangup, mute etc.) is totally working. For me this is mostly about music controls, so I'm not too worried about the call controls and haven't looked into fixing that so far.

By the way, I found out a modified Generic.kl file is enough to cause updates to fail (for ZVC anyway), so you'll want to keep a copy of the original to restore for cases like that.

If you still can't get it to work, what exactly is happening for you, and what app are you using? Did you map MEDIA_NEXT, or MEDIA_PLAY_PAUSE? The Headset Button Controller app I'm using (free trial also) has a troubleshooting feature where it displays the button presses it sees on screen, whether it takes action on it or not, which could be useful to figure things out.
7th July 2014, 12:21 AM   |  #7  
Junior Member
Flag Bronx
Thanks Meter: 1
 
15 posts
Join Date:Joined: Aug 2012
doesnt work
Quote:
Originally Posted by ChoppedLiver

My phone is LG G2 on Sprint (LS980), and it actually does work for me.

Since my above post, I have actually changed the mapping again to MEDIA_NEXT, and I'm using the Headset Button Controller app (https://play.google.com/store/apps/d....headsetbutton). The actions in the controller app are all set under "Right button actions" (so exactly according to step 6 in the OP..).

I think any app that will let you configure things for a 3rd/right button should work. The JAYS one is free, but as I recall it asked for a permission I wasn't comfortable with, and I ended up with Kober's app instead, which I think was $2 and to me well worth it (you can barely get a coffee for that these days..). There is a free trial.

This setup works great for music controls (play/pause, next/previous, volume control), but it doesn't seem call control (answer/hangup, mute etc.) is totally working. For me this is mostly about music controls, so I'm not too worried about the call controls and haven't looked into fixing that so far.

By the way, I found out a modified Generic.kl file is enough to cause updates to fail (for ZVC anyway), so you'll want to keep a copy of the original to restore for cases like that.

If you still can't get it to work, what exactly is happening for you, and what app are you using? Did you map MEDIA_NEXT, or MEDIA_PLAY_PAUSE? The Headset Button Controller app I'm using (free trial also) has a troubleshooting feature where it displays the button presses it sees on screen, whether it takes action on it or not, which could be useful to figure things out.

Im sooooo confused by this but is it possible for you to screen shot your settings for Generic.kl? im sorry for the late reply
7th July 2014, 02:43 AM   |  #8  
Member
Flag Atlanta, GA
Thanks Meter: 11
 
45 posts
Join Date:Joined: Dec 2012
More
Quote:
Originally Posted by pabel101

Im sooooo confused by this but is it possible for you to screen shot your settings for Generic.kl? im sorry for the late reply

The whole file is over 400 lines long, so a bit too long to fit in a screenshot. There are only 2 lines that you will need to touch however, and they will look like this when you are done with them:

Code:
key 163   HEADSETHOOK

key 226   MEDIA_NEXT
Note that these lines are not next to each other, but they are easy enough to find as they are pretty much ordered by key "number" as you can see.

Sorry if I made things sound confusing.. the steps in the OP are maybe more clear, and exactly what you need to do to get Generic.kl modified the way mine is. Feel free to ask if you need more help/clarification though.
The Following User Says Thank You to ChoppedLiver For This Useful Post: [ View ]
7th July 2014, 04:05 AM   |  #9  
Junior Member
Flag Bronx
Thanks Meter: 1
 
15 posts
Join Date:Joined: Aug 2012
playpause
Quote:
Originally Posted by ChoppedLiver

The whole file is over 400 lines long, so a bit too long to fit in a screenshot. There are only 2 lines that you will need to touch however, and they will look like this when you are done with them:

Code:
key 163   HEADSETHOOK

key 226   MEDIA_NEXT
Note that these lines are not next to each other, but they are easy enough to find as they are pretty much ordered by key "number" as you can see.

Sorry if I made things sound confusing.. the steps in the OP are maybe more clear, and exactly what you need to do to get Generic.kl modified the way mine is. Feel free to ask if you need more help/clarification though.

ok i did what you said and now my middle button Just skips to next track is that alright?
7th July 2014, 04:31 AM   |  #10  
Member
Flag Atlanta, GA
Thanks Meter: 11
 
45 posts
Join Date:Joined: Dec 2012
More
Quote:
Originally Posted by pabel101

ok i did what you said and now my middle button Just skips to next track is that alright?

Yes, this means the re-mapping of the button worked. Now you can use one of the headset control apps to program the button as you please (remember this button is now acting as the "next" or right button, so program as such).

But, you say "middle button" - do you have a 3 button headset? If yes, I think you could have left the mapping alone, and programmed either of the left/right buttons, or both. Not really sure of the best and most functional approach in this case, I've never had anything other than a single button headset. I would think with 3 buttons, if all 3 are supported, you can have some more flexibility.

If you do have a 3 button headset, but only the middle button is supported by Android at all (apparently YMMV depending on the make/model among other things), then ignore everything I just said, keep the mapping as-is, and just program the one working button as you like - still as if it were the right button.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in G2 Q&A, Help & Troubleshooting by ThreadRank