Android Recording Incoming and Outgoing Calls

55,709

Solution 1

First off, you have to be careful with recording calls as there are legal requirements depending on the country.

Here is a blog post on how to record audio using the MediaRecorder.

I haven't tried recording phone call's but there is a option in MediaRecorder AudioSource for:

  • VOICE_CALL - Voice call uplink + downlink audio source
  • VOICE_DOWNLINK - Voice call downlink (Rx) audio source
  • VOICE_UPLINK - Voice call uplink (Tx) audio source

As long as the audio source options work, you should be good to go.

Solution 2

I am using mic to record calls for better support and compatibility.

MediaRecorder recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(your_desired_folder_path);
 try {
    recorder.prepare();
} catch (java.io.IOException e) {
    recorder = null;
    return;
}
recorder.start();

Solution 3

I am using mic to record phone audio and also use the Telephony manager to find the calling state.

private MediaRecorder recorder;

  recorder = new MediaRecorder();
        try {
            recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setAudioSamplingRate(44100);
            recorder.setOutputFile(your_desired_files_absoulte_path);
} catch (Exception e) {
e.printstacktrace ;
}

after that, you can easily start recording anywhere you want

recorder.prepare();
recorder.start();

and after finishing recording you can easily also stop the recording

recorder.stop();
recorder.reset();
recorder.release();
Share:
55,709
Harsha M V
Author by

Harsha M V

I turn ideas into companies. Specifically, I like to solve big problems that can positively impact millions of people through software. I am currently focusing all of my time on my company, Skreem, where we are disrupting the ways marketers can leverage micro-influencers to tell the Brand’s stories to their audience. People do not buy goods and services. They buy relations, stories, and magic. Introducing technology with the power of human voice to maximize your brand communication. Follow me on Twitter: @harshamv You can contact me at -- harsha [at] skreem [dot] io

Updated on August 10, 2020

Comments

  • Harsha M V
    Harsha M V almost 4 years

    I am trying to understand is there a way I can record calls incoming and outgoing on android phones 2.2 and above?

    A client wants to record calls of the agents they make to the clients so that it can be later used to fill out some material. Instead of making the client wait while on call they want to do it later on.

    Is this possible and what APIs do I need to use?

  • Auto-Droid ツ
    Auto-Droid ツ over 11 years
    VOICE_CALL - Voice call uplink + downlink audio source VOICE_DOWNLINK - Voice call downlink (Rx) audio source VOICE_UPLINK - Voice call uplink (Tx) audio source are not working in android 4.0 do you have any idea on it
  • TAHA SULTAN TEMURI
    TAHA SULTAN TEMURI about 7 years
    Sorry but microphone reocord voice of receiver not incoming user voice.
  • Bhanu Sharma
    Bhanu Sharma almost 7 years
    HI all i faced same issue( Not getting other side voice ) with Samsung S7 and S8 other wise my prog is run very well on rest of phones Any idea about ??
  • Imran Khan Saifi
    Imran Khan Saifi almost 7 years
    Successfully record the caller voice only using "blog post" link. But unable to record receiver end voice... Why ?
  • Bhupesh
    Bhupesh over 6 years
    To make it more clear. These AudioSources need CAPTURE_AUDIO_OUTPUT permission. Which is only granted to system applications. Second thing AudioSource.VOICE_COMMUNICATION doesn't need that permission and works well on pre 7.0 devices. But that doesn't record other side's voice on devices running 7.0 and above.
  • Anand Savjani
    Anand Savjani about 6 years
    I have implemented this code but incoming call starts recording after few seconds. Please provide solution or suggestion for time management
  • android enthusiast
    android enthusiast almost 6 years
    This just opens the mic and starts recording. It has nothing to do with a call.
  • Bilal Shahid
    Bilal Shahid almost 6 years
    yes it is and this is the best way you will find to record because on some phones recording is not allowed.
  • Jayavinoth
    Jayavinoth over 5 years
    Seems only system apps can use the VOICE_CALL, UPLINK and DOWNLINK. I was tried lot of call recorder coding in my Lenovo Zuk Z2 plus mobile with several audio sources but none of them are worked in recording the receiver voice. Cube ACR and Automatic call recorder apps are working perfectly in my mobile. Anyone please let me know how they can achive it?