Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,768,490 Members 50,365 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE] Take Back Your Headset Controls!

Tip us?
 
IAmAN00bie
Old
(Last edited by IAmAN00bie; 17th December 2012 at 03:51 AM.) Reason: updated for Nexus 4 and formatting
#1  
IAmAN00bie's Avatar
Senior Member - OP
Thanks Meter 340
Posts: 619
Join Date: Dec 2010
Default [GUIDE] Take Back Your Headset Controls!

REQUIREMENTS
  • ROOT ACCESS
  • SINGLE-BUTTON HEADSET
  • ANDROID 4.1+

PREFACE

TESTED ON THE NEXUS 4 RUNNING 4.2

If you often listen to music using a single-button headset (the kind that many Samsung devices tend to ship with), then you should know that Google lets you control the headset button. By default, you can:
  • Play/Pause (Single Press)
  • Skip track (Double Press)
  • Launch Voice Search (Single-click Long Press)

Pretty cool, right? So what's the deal, then?

The issue is you CANNOT customize how you want the system to respond to your button input.
  • What if you want to long press to increase volume?
  • What if you want to triple click to go to the previous track?
  • What if you want to double click and hold to decrease volume?
  • What if you want to launch an app besides Google Voice Search (I personally have bound utter! in place of Google's search!)?

Nope, too bad.

Well, there is a workaround for this.

How does it work?

In /system/usr/keylayout, two files called Generic.kl and hs_detect.kl reside where you can modify the keymapping of the HEADSETHOOK input to an alternate key that is normally found on a 3-button headset, specifically MEDIA_NEXT. Then, you can modify how the system responds to MEDIA_NEXT by using a headset control app.

TO FIX:

**NOTE: ITEMS SURROUNDED BY A BLUE BOX MEAN IT IS THE ORIGINAL VALUE WHILE ITEMS SURROUNDED BY A RED BOX MEANS IT IS THE NEW VALUE**

1) Install the Keytest App found here: https://github.com/chrisboyle/keytest/downloads

2) Once inside the app, press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_HEATSETHOOK
scanCode=226
as shown in the following picture: http://i.imgur.com/dogxm.png


3) Using a root-enabled file explorer app (I personally use Solid Explorer), go to /system/usr/keylayout and make a backup of Generic.kl and hs_detect.kl (copying them to your internal storage, for example /sdcard/headset).

4) You will modify these two files on two different lines. The folder should look like this: http://i.imgur.com/ShpCv.png


Generic.kl:
ORIGINAL: http://i.imgur.com/dzmPy.png AND http://i.imgur.com/bdRRz.png

NEW: http://i.imgur.com/ZddZT.png AND http://i.imgur.com/PPAZk.png

hs_detect.kl:
ORIGINAL: http://i.imgur.com/dVaXK.png

NEW: http://i.imgur.com/Deh9r.png NOTE: I MANUALLY ADDED THE KEY 163 LINE IN

Simple right? You are just flipping the two values essentially.

5) Save the changes. Reboot.

6) Open the Keytest app again. Press the headset button. On your screen, it should read as follows:

Code:
keyCode=KEYCODE_MEDIA_NEXT
scanCode=226
as shown in the following picture: http://i.imgur.com/2BSHM.png

7) Now all you need to do is use an app to configure the MEDIA_NEXT key to your liking.

MEDIA_NEXT is a key typically found on 3-button headsets, symbolized by the "Right" key. An app like Headset Button Controller or Headset Droid should do the trick. Both are paid apps, but there are trial versions available. If there are any free alternatives that can do the trick, let me know and I'll add it in! (I am NOT in any way affiliated with the app developers!)

LIMITATIONS
1)A ROM update will wipe/reset the files.

1a) How can you avoid this? Pretty simple, actually! Just keep a backup of Generic.kl and hs_detect.kl after you make the changes to them, and inject them into the zip file before you flash the ROM. You can also use the following script to do this which needs to be run as root, given that you have the two files backed up in /sdcard/headset

Code:
mount -o rw,remount /system

cp -f /sdcard/headset/* /system/usr/keylayout

chmod 644 /system/usr/keylayout/*

mount -o ro,remount /system

2) An actual or simulated "MEDIA_NEXT" input will now not be recognized as a MEDIA_NEXT. This will affect, for example, 3-button headsets or tasker tasks that simulate a MEDIA_NEXT input. Also: ROMs with the long-press to skip tracks will no longer skip track on holding volume-up, as this is no longer recognized as a MEDIA_NEXT input.

2a) How can you avoid this? You can instead use a different key to be replaced rather than MEDIA_NEXT, if you so desire. The work-up will be the exact same, only the values you swap will be different.


CREDITS
Device: Google Nexus 5
ROM: Paranoid Android
Kernel: Trinity Kernel

XDA Tribute: http://www.youtube.com/watch?v=gLK5CwVVEiA
The Following 34 Users Say Thank You to IAmAN00bie For This Useful Post: [ Click to Expand ]
 
IAmAN00bie
Old
#2  
IAmAN00bie's Avatar
Senior Member - OP
Thanks Meter 340
Posts: 619
Join Date: Dec 2010
Please respond to this post if it worked for you! I don't have my Nexus 4 yet, but I am absolutely positive it works on it as well! It worked for my GNexus on 4.1 and 4.2, and it has worked across many other devices as well.
Device: Google Nexus 5
ROM: Paranoid Android
Kernel: Trinity Kernel

XDA Tribute: http://www.youtube.com/watch?v=gLK5CwVVEiA
 
IAmAN00bie
Old
#3  
IAmAN00bie's Avatar
Senior Member - OP
Thanks Meter 340
Posts: 619
Join Date: Dec 2010
Bump for visibility!

Sent from my Galaxy Nexus using Tapatalk 2
Device: Google Nexus 5
ROM: Paranoid Android
Kernel: Trinity Kernel

XDA Tribute: http://www.youtube.com/watch?v=gLK5CwVVEiA
 
brandall
Old
#4  
brandall's Avatar
Senior Member
Thanks Meter 4543
Posts: 2,618
Join Date: May 2008
Location: Birmingham

 
DONATE TO ME
Thanks for this It'll help me hunting for why I can't get the headset working properly in utter! !
Devices: Desire|Wildfire|Sensation|Flyer|SIII|Hudl|N4|7|10


Tasker: The Ultimate Noob/Beginners Guide

Memotion:
Latest BETA Build Here: V1.1.7B

utter! Latest Play Store Build Here: V3.1.1B


Quote:
Originally Posted by Tinasintunes View Post
Ohhhhh @brandall Ohhhh @brandall you're the best doo dum dee dee doooooo dummmmm
The Following User Says Thank You to brandall For This Useful Post: [ Click to Expand ]
 
tssphysicsboi
Old
(Last edited by tssphysicsboi; 18th November 2012 at 09:59 AM.)
#5  
Senior Member
Thanks Meter 15
Posts: 139
Join Date: May 2011
Works PERFECT! THANKS!!!! (for nexus s)
 
1234568
Old
#6  
Senior Member
Thanks Meter 214
Posts: 608
Join Date: Nov 2010
https://play.google.com/store/apps/d...headsetcontrol

I used to use this app. It offered the same functionality without having to tweak any files. I have not tested on n4 though.
 
tssphysicsboi
Old
#7  
Senior Member
Thanks Meter 15
Posts: 139
Join Date: May 2011
Quote:
Originally Posted by 1234568 View Post
https://play.google.com/store/apps/d...headsetcontrol

I used to use this app. It offered the same functionality without having to tweak any files. I have not tested on n4 though.
This tweak is meant for long press problem only opening google now. Even Jays says this

"Compatibility
- Click-and-hold actions will not work in Android 4.1+ as Google Now intercepts them."

so even if you use jays your long press should not work unless your rom has helped you change it!
The Following User Says Thank You to tssphysicsboi For This Useful Post: [ Click to Expand ]
 
PMaksymiuk
Old
#8  
Member
Thanks Meter 21
Posts: 79
Join Date: Feb 2012
Location: Warsaw
Used this app back in the day before i got my MW600..

https://play.google.com/store/apps/d...id=tvk.headvol
 
IAmAN00bie
Old
#9  
IAmAN00bie's Avatar
Senior Member - OP
Thanks Meter 340
Posts: 619
Join Date: Dec 2010
Quote:
Originally Posted by PMaksymiuk View Post
Used this app back in the day before i got my MW600..

https://play.google.com/store/apps/d...id=tvk.headvol
Yes, Headset Droid is another option for users who don't want to use Headset Button Controller!
Device: Google Nexus 5
ROM: Paranoid Android
Kernel: Trinity Kernel

XDA Tribute: http://www.youtube.com/watch?v=gLK5CwVVEiA
 
IAmAN00bie
Old
#10  
IAmAN00bie's Avatar
Senior Member - OP
Thanks Meter 340
Posts: 619
Join Date: Dec 2010
I just received my Nexus 4 earlier today, and I saw that there were some changes done in the /system/usr/keylayout folder. I managed to fix the problem, and will update the OP with new pictures ASAP for those looking to fix the headset problem.
Device: Google Nexus 5
ROM: Paranoid Android
Kernel: Trinity Kernel

XDA Tribute: http://www.youtube.com/watch?v=gLK5CwVVEiA

Tags
control, fix, guide, headset, voicesearch
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes