I wanted to use the speaker outlet of android even though a headphone is connected (only for one activity) so the code I wrote is:
AudioManager audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.STREAM_MUSIC);
audioManager.setSpeakerphoneOn(true);
in the oncreate() method of that activity and it worked but in another activity I don't want the same thing to happen. I want the sound to be played in the headphone if headphone is connected and through speaker if headphone is not connected but even in the other activity the sound is played only on speaker even though headphone is connected. Can someone help and tell me where am I going wrong.