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?
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.
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.
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 ().
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.
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" />
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