Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioManager.isWiredHeadsetOn() is not working in android

I want to check whether heaset is plugged in or not... I did it like this

 AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
 Log.i("am.isWiredHeadsetOn()", am.isWiredHeadsetOn()+"");

But i am always getting false value...

Why is this happening?

like image 254
coderslay Avatar asked Jun 06 '11 09:06

coderslay


People also ask

What is the use of audio manager in Android?

AudioManager is a class provided by Android which can be used to control the ringer volume of your Android device. With the help of this Audio Manager class, you can easily control the ringer volume of your device.

How to control ringer volume of Android device with audio manager?

AudioManager is a class provided by Android which can be used to control the ringer volume of your Android device. With the help of this Audio Manager class, you can easily control the ringer volume of your device. Audio Manager Class can be used by calling the getSystemService () method in Android.

How is audio focus handled on Android?

Audio focus is handled differently depending on the version of Android that is running: Beginning with Android 2.2 (API level 8), apps manage audio focus by calling requestAudioFocus () and abandonAudioFocus ().

What is audiofocusrequest in Android?

The AudioFocusRequest contains information about the audio context and capabilities of your app. The system uses this information to manage the gain and loss of audio focus automatically. Beginning with Android 8.0 (API level 26), when you call requestAudioFocus () you must supply an AudioFocusRequest parameter.


1 Answers

It looks like this is a bug. You will always get false when calling isWiredHeadsetOn unless your add MODIFY_AUDIO_SETTINGS permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
like image 84
inazaruk Avatar answered Oct 10 '22 09:10

inazaruk