I have used below code to check that headset connected or not in onCreate Mehod.
But every time it gives me output of not connected.
AudioManager audio=(AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if(audio.isWiredHeadsetOn()){
Toast.makeText(this,"Connected",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this,"Not Connected",Toast.LENGTH_SHORT).show();
}
Anybody can tell what's wrong with above code.
Thank You.
Add this permission in your menifest file
<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