applications – Audio routing in Android

I am developing an android app which is recording audio from Bluetooth headsets. I also want to listen this recording audio real time from wired headphones connected to my android mobile.
I am done with Bluetooth recording but unable to direct the audio to wired headphones.

I am using audioTrack to play the audio, I tired:

mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setSpeakerphoneOn(false);
mAudioManager.setWiredHeadsetOn(true);
mAudioManager.setRouting(AudioManager.MODE_IN_COMMUNICATION, AudioManager.ROUTE_HEADSET, AudioManager.ROUTE_BLUETOOTH_SCO);

Then I realized that in new android version we have specify the preferred audio device so I tired:

AudioDeviceInfo() devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
for (AudioDeviceInfo device : devices) {
   if (device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET || device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES) {
     audioTrack.setPreferredDevice(device);
   }
}

This works but the audio is too noisy and it seems like it also switches mobile microphone on. As I have started receiving extra audio too.

Please help me to find a perfect solution for this. or a perfect platform to ask this question.