I just wanted to make a app that works as an loudspeaker. Whatever gets into microphone(headphones) must be played through external speaker. I tried some and i followed the following link procedures but i couldn't make it. Is there any other way i can get this out. Please help me. Thanks in advance.
Android - Getting audio to play through earpiece
how to play sound from microphone to speaker directly on android?
boolean isRecording; //currently not used
AudioManager am;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    Record record = new Record();
    record.run();
}
public class Record extends Thread
{
    static final int bufferSize = 200000;
    final short[] buffer = new short[bufferSize];
    short[] readBuffer = new short[bufferSize];
    public void run() {
        isRecording = true;
        android.os.Process.setThreadPriority
        (android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
        int buffersize = AudioRecord.getMinBufferSize(11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT);
        AudioRecord arec = new AudioRecord
        (MediaRecorder.AudioSource.MIC,
                11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                buffersize);
        AudioTrack atrack = new AudioTrack
        (AudioManager.STREAM_VOICE_CALL,
                11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                buffersize,
                AudioTrack.MODE_STREAM);
        am.setRouting(AudioManager.MODE_NORMAL,
                AudioManager.ROUTE_EARPIECE,
                AudioManager.ROUTE_ALL);
        Log.d("SPEAKERPHONE", "Is speakerphone on? : " + am.isSpeakerphoneOn());
        atrack.setPlaybackRate(11025);
        byte[] buffer = new byte[buffersize];
        arec.startRecording();
        atrack.play();
        while(isRecording) {
            arec.read(buffer, 0, 
                    buffersize);
            atrack.write(buffer, 0,
                    buffer.length);
        }
        arec.stop();
        atrack.stop();
        isRecording = false;
    }
}