recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}
recorder.start();

Source: https://issuetracker.google.com/issues/36907207?pli=1 msg# 504
Update: according to https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html it should use VOICE_CALL instead of MIC.