Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Checking if headphones are plugged in

Tags:

android

How can I check if headphones are currently plugged in. I don't want a broadcastreceiver which informs me when they have been connected to the device. I need something like:

if(/*headphone is connected*/)
 ...
like image 527
user283494 Avatar asked May 04 '10 11:05

user283494


People also ask

How do you check whether a headset is plugged into an Android device?

If so, there's an intent to detect whether or not one is being plugged or unplugged: ACTION_HEADSET_PLUG . To check the status, you can use AudioManager. isWiredHeadsetOn() , although that may return false if there is also a bluetooth headset, and audio is routed to that instead.

How do you check if headphones are connected?

Activate the Test Call or similar feature. Typically you do this by selecting a dummy contact labeled Test Call or something similar from your contacts list, and then initiate a call. When you speak into the microphone, you should be able to hear your voice played back over the headphones.

Why does my Android phone think headphones are plugged in?

Clean the headphone jack It's possible that your phone can't get out of headphone mode because it has a lot of debris inside the audio jack. Dust, dirt, and even lint can build up inside. If you keep your phone inside your pocket regularly, lint can collect inside the jack.


2 Answers

It looks like you'll be interested in the isWiredHeadsetOn() method and isBluetoothA2dpOn() method of the AudioManager class.

However, the isWiredHeadsetOn() method is only available in Android 2.0 or later. (The isBluetoothA2dpOn() method has been available since Android 1.5.)

like image 72
Dave Webb Avatar answered Nov 08 '22 16:11

Dave Webb


Use this code snippet

AudioManager am1 = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
Log.i("am1.isWiredHeadsetOn()", am1.isWiredHeadsetOn()+"");
Log.i("am1.isMusicActive()", am1.isMusicActive()+"");
Log.i("am1.isSpeakerphoneOn()", am1.isSpeakerphoneOn()+"");
like image 31
Mohsin Bagwan Avatar answered Nov 08 '22 17:11

Mohsin Bagwan