Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether headphones are plugged in

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?

like image 566
dosse91214 Avatar asked May 06 '13 08:05

dosse91214


People also ask

How do you check if headphones are plugged in Windows?

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.

Why won't my PC detect my headphones?

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.

How do I check my headphone connection?

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.

Why does my computer say my headphones are plugged in?

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.


1 Answers

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 +

like image 181
Naskov Avatar answered Sep 21 '22 11:09

Naskov