Voice call recording on Android Lollipop and higher version do not work

I am having trouble recording a voice call in android lollipop and later. By this code I can record my voice, but I could not record the voice of another person.

public void startRecording() { if (recording == false) { Log.e("here", "--------Recorder_Sarted------" + fname); SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy"); int randomPIN = (int) (Math.random() * 9000) + 1000; recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); String file = Environment.getExternalStorageDirectory().toString(); String filepath = file + "/Aeris/Recording"; File dir = new File(filepath); dir.mkdirs(); Log.e("here ", "----------------" + sdf.format(Calendar.getInstance().getTime()) + " " + fname + " " + type); filepath += "/" + type + "-" + fname + "-" + sdf.format(Calendar.getInstance().getTime()) + "-" + randomPIN + ".3gp"; recorder.setOutputFile(filepath); try { recorder.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } recorder.start(); recording = true; } } 

This code works fine under the winch version for Android. please help me solve this problem.

+6
source share
1 answer

Chane the AudioSource VOICE_COMMUNICATION to MIC (Microphone)

 recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); 

Tested in Moto g2 (Android 6.0), Lenovo (Android 5.0), works great.

0
source

All Articles