If this problem is caused by an app you installed on your device, all you need to do is to uninstall it. To test if an app is causing the issue, boot your device into safe mode. To boot it into safe mode, press and hold the Power (sleep/wake) button, while your device is turned on, and tap and hold the Power off option until a "safe mode" prompt appears on the screen. If the headphones are recognized in safe mode, an app is definitely the problem.
See the don't know how to uninstall a program / an application guide to learn how to uninstall apps.
Note: The process of accessing the safe mode might differ from one device to another, depending on the manufacturer. If the above-mentioned method didn't work for you, type your device's model number and search on the Internet.
If your device is unable to recognize headphones and you have tried cleaning the device's headphones port and headphones jack, try wiping the cache partition via the recovery menu.
To access the recovery mode and wipe the cache partition follow these steps:
If you don’t receive the email in the next 2 minutes please check your junk folder, and add [email protected] to your safe sender list.