8

I am developing an Android app for recording calls. This is my code snippet.

    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setOutputFile(file_path);

This is working perfectly for devices below android 7, but when I use Android 7 mobile devices I can hear only outgoing voice but cannot hear incoming voice.

Can anyone help me in fixing it?

Sudarshana Dayananda
  • 5,165
  • 2
  • 23
  • 45

4 Answers4

4

Use VOICE_COMMUNICATION as AudioSource as it is microphone audio source tuned for voice communications such as VoIP, as described on Android Developers site.

I tried using VOICE_CALL(Uses audio uplink and downlink recording) but it can be used only by system components only, So mic is only option to record audio.

TRY:
1: Sliding up the volume during call.
2. DO NOT use headphones as audio will not be recorded by mic in some cases[Haven't tried this]. 3. Works on Moto G4 Play, Android version 7.1.1(most of Motorola phones have two mics):

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

global_warming
  • 833
  • 1
  • 7
  • 11
  • I think the problem lies with the phone you are using, as you are able to record outgoing voice. The mic placement on your phone is in such a way that it can't record incoming in normal mode. Did you tried using speakerphone? – global_warming Nov 29 '17 at 09:35
3

Well, the problem is that you only record the microphone input with that code, which is obviously just the outgoing voice. To also record the incoming voice, you'd have to also record system sound.

To record system sound, you'll have to google a bit. Here are some stackoverflow links that should get you started:

In the end, you'd also have to merge the two soundtracks into one file to have the whole call as one.

Twometer
  • 1,561
  • 2
  • 16
  • 24
  • That must have a different reason, because the code you posted only records microphone input sound. – Twometer Nov 22 '17 at 13:37
2
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

try using this

Manoj kumar
  • 450
  • 4
  • 13
2

this code works like a charm for Android 7 built with API 25,

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);