I can't seem to find a way to know on android if the headphones are plugged in. I found various solutions but they always seem to return false. The only thing that seems to work properly is a BroadcastReceiver
, but that's not what I need:
I just need something like this
if(headphones plugged in) { }
Is there such a function? Does it require some special permissions?
Check the audio jack. On the back of your laptop or desktop, look for the audio output port, often labeled with a headphone or speaker icon, and make sure the headphones are plugged in.
Your computer not recognizing your headphones is a fairly common issue in Windows 10 PCs. It could be caused by a corrupt or outdated driver, faulty USB ports (if your headset uses USB), an error in the connection (in case of Bluetooth, for example), or an issue with the headphones themselves.
Here's how: Right-click on the sound icon on the lower-right of your computer screen, then click Sounds. Click the Playback tab, unplug and then re-plug your headphone into the headphone jack to make sure Headphones (or Speakers/Headphones, same as below) is checked, then click OK.
One of the most common reasons why mobile devices are stuck in headphone mode is because of dirt and debris stuck inside the audio jack. That's why it's important to keep in mind that not only do you need clean headphones, you need to have a clean headphone jack as well.
You can use this code for checking if the headset is plugged in
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.isWiredHeadsetOn();
(Don't worry about the deprecation, it's still usable for ONLY checking if the headset are plugged in.)
And you need <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Available in Android 2.0 +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With