[MOD] Headset Control on Stock ROM
This MOD will allow for Wired headset controls with your headset so that you can control volume, and track control. It will also allow for using the mic for voice control through Google Voice Search. I created this thread because on KitKat ROMs, headset control works automatically, but the KitKat ROMs have worse performance because they are not optimized for the Snapdragon 800 SoC or HTML5. Now you can go back to stock and have all the features you like, such as KnockOn and HTML5 support, and Headset Control. No more Call / redial when pressing middle click button.
Go into /system/usr/keylayouts/Generic.kl and edit the line "key 226 HEADSETHOOK" to "key 226 MEDIA_PLAY_PAUSE"
This will make the middle click button on your headset play or pause tracks.
Note: You can replace the "HEADSETHOOK" with whatever action you wish such as MEDIA_NEXT or MEDIA_PREVIOUS. In order to stop the redial from occurring whenever you press the middle button on the headset you have to change the key 226 value. If you leave the key 226 blank then you won't be able to use Xposed Additions but you will have successfully disabled redial.
You will have to reboot for effect to take place of course.
Option Step (For more configurability)
Download and install Xposed Framework
Open the Framework, and download the Xposed Additions under Modules. Enable the Module, and reboot for changes to take effect.
Open the Xposed Additions module, under "Re-map Settings" option, select "Add new button." Plug in headphones. Press the headphone button (middle button) and it will recognize it as a key.
Xposed additons allows you to configure settings for when the screen is off and when it is on. You should configure both "Screen Off" and "Screen On" so that headset control works when screen is on or off. By default, "Screen On" is set to be configured.
Configure the "Click Action" as Media Play/Pause.
( This step allows you to configure long press to open voice control, and to do volume and Next/Previous Track Control)
Now the middle click button on your headset will be able to play and pause music. To add volume control and enable voice control, you can then download JAYS Headset Control
which is free from the Google Play Store.
Also download Voice Search Shortcut
(If you do not then when you configure JAYS Headset Control, you will only have the option to launch the regular Google Voice Search, which requires saying "Ok Google" first. But if you configure it to launch this VS Shortcut app, then when you activate the app it will begin listening for dictation directly.)
Once installed, open the JAYS Headset Control app. You must select 3-button controller, not 1-button. Then set it to Advanced Mode.
Under "Button Actions" configure "Click and Hold" which alows you to configure the long press action. Configure it to "Launch App" and select "VS Shortcut" so that when you long press it will immediately allow for voice dictation to make calls, ask for weather, stocks, sport scores, set alarms, etc.
Configure and explore the other options as you see fit to meet your needs. You can configure the "Double Click and Hold" and "Triple Click and Hold" to do volume control.
Using JAYS Headset Control will disable the ability control tracks using the hardware volume buttons (that's if you have enabled this option in Gravity Box or G2 Xposed) You should disable the volume key control in Gravity Box or Xposed if you are using JAYS Headset Control otherwise when you press the volume key when the screen is off, the volume down will increase volume and the volume up will register as volume down. It's a weird result of enabling headset control, but a necessary sacrifice. Unless... you read more below for another solution.
Enable Volume Key for Track Control
If you wish to be able to have hardware volume key track control and headset control, then follow this method.
Disable JAYS Headset Control. Enable Volume Key Control using Gravity Box or Xposed. Download Ultimate HeadSet Controller
, a free app from the Google Play Store. Using this app you can lower and raise volume, and get the ability to have triple click as previous track. However this means that there is no way to do a long press and have the voice search come up. If you would rather voice search, then continue reading.
Disable JAYS Headset Control. Enable Volume Key Control using Gravity Box or Xposed. Get Xposed Additions Pro. You can find it floating around the internet with a simple google search "Xposed Additions Pro apk"
(Allows Double Click setting and Long Click)
Once installed, make sure the module is enabled in Xposed, then set "Double Click" for Next Track and "Long Press" as Previous. For the "Screen On" you can set "Long Press" to be Search and have the indirect voice search whereby you have to first pause the music before it will allow you to use the mic, and if you did not pause before you did the long press, then pausing the music after the long press won't activate the mic. For the "Screen Off" unfortunately there is no option to do select Search as the action therefore you can use Previous as the action since there is no triple click setting in this app. If you must have the option to go to previous track, then set "Long Press" for "Screen On" and "Screen Off" to Previous but you sacrifice voice search.