in my application, I need to direct sound from microphone directly to speaker. No other actions. I found a way to direct sound from microphone to earpiece by playing a file and setting speaker off. So I guess speaker can work similarly. However I don' know how to get rid of the playing file thing. Thank you.
speaker() {
m_audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_audioManager.setSpeakerphoneOn(true); // not needed I think
//m_audioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); earpiece need this?
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);
use AudioRecord & AudioTrack to record & play (change to ..._MUSIC if speaker needed