I am making an android app for testing phones and I need to be able to play a tone via the earphone speaker while headphones are plugged in. I am able to get the tone to play via the ear speaker when the headphones are not plugged in, but not when they are plugged in. Is there anyway to get my tone to play via the ear speaker when the headphones are plugged in? I will include the code that works without the headphones in.
mp = MediaPlayer.create(getApplicationContext(), R.raw.tone_1ghz_5sec);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
//set to false for through headphones
audioManager.setSpeakerphoneOn(false);
mp.start();
In other activities, I used the audio system class to force the speakers, is this the key here?