I used the code below to verify that the headset is connected or not in onCreate Mehod.
But each time it gives me an output 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();
}
No one can say what is wrong with the code above.
Thank.
Nirav source
share