18

I tried it and use the following code for recording outgoing calls but it does not..

  @Override
  public void onReceive(Context context, Intent intent) 
  {
          this.context = context;
          if (intent.getAction().equalsIgnoreCase(Intent.ACTION_ANSWER)) 
          {
              try
              {
                  phonenbr = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
                  Log.v("GDHGDHGHDGDHGDHGHDGHDGH", phonenbr);
                  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                  recorder.setOutputFile(pathname);
                  recorder.prepare();
                  recorder.start();
                  recordstarted = 1;
                  telManager= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }


              final PhoneStateListener phoneListener = new PhoneStateListener()
                {
                    @Override
                     public void onCallStateChanged(final int state, final String incomingNumber)
                        {
                            getTelephonyOverview(telManager);
                        }
                };

           telManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

}

}

           public void getTelephonyOverview(final TelephonyManager telManager)
           {
                   int callState = telManager.getCallState();
                   switch (callState)
                   {
                    case TelephonyManager.CALL_STATE_IDLE:
                    {
                        if (recordstarted==1)
                        {
                            recorder.stop();
                            recordstarted =0;
                        }
                        break;
                    }
                }
           }

Please provide some good solution for this problem..

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • if u can provide catlog of errors, then i might help.. – manidhar mulaparthi Aug 05 '10 at 13:35
  • hi there, I am also in need of recording phone calls. Did you you get a chance to make it working? – Umair A. Aug 28 '10 at 18:53
  • 1
    Cool idea, but before you get too far I suggest that you check out your local laws that relate to privacy and recording telephone calls. I know that in the US there are very strict rules as to what can be recorded and notifying the user that they are being recorded. – bakoyaro May 10 '11 at 13:16

5 Answers5

5

This can be solved with API level 8+. Set your audio source for media recorder as phone uplink, downlink, or both.

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); //Voice downlink/ Uplink
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(AudioEncoder.AAC );

But beware of the law and regulations before doing this.

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
Sojan P R
  • 536
  • 6
  • 9
  • 1
    I tried this on my Droid X, but I keep getting "stop failed: -1007" RuntimeException from MediaRecorder on recorder.stop(). recorder.start() passes without issue and a non zero sized file is created, but is unplayable. – CompEng88 Oct 01 '12 at 02:38
  • Which phones have you tried this on? It looks like a too simple solution to be true... and then they tend to be :) – rrostt Nov 23 '12 at 22:46
4
  1. You cannot record phone calls very well in Android, because the in-call audio is not available to SDK applications
  2. ACTION_ANSWER is not a broadcast Intent
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

You cannot record call simply by media recorder. you have to also change the setting of audio manager and put the loud speaker on before starting recording and the audio source will remain same(mic).So try to edit audio manager's setting


AudioManager audiomanager = (AudioManager)context.getSystemService("audio"); 
int i = audiomanager.getRouting(2); 
audiomanager.setMode(2);
audiomanager.setMicrophoneMute(false);
audiomanager.setSpeakerphoneOn(true); 
int j = audiomanager.getStreamMaxVolume(0); 
if(j < 0) 
     j = 1; 
int k = j / 2 + 1; 
audiomanager.setStreamVolume(0, k, 0); 
audiomanager.setRouting(2, 11, 15);
Shaihi
  • 3,952
  • 4
  • 27
  • 47
Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
  • but how to put the loud speaker on ? – Kartik Bhatt Jul 04 '11 at 09:11
  • @Kartik You need to add change audio setting permossion in your mainfeast file. Here is my code : `AudioManager audiomanager = (AudioManager)context.getSystemService("audio"); int i = audiomanager.getRouting(2); audiomanager.setMode(2); audiomanager.setMicrophoneMute(false); audiomanager.setSpeakerphoneOn(true); int j = audiomanager.getStreamMaxVolume(0); if(j < 0) j = 1; int k = j / 2 + 1; audiomanager.setStreamVolume(0, k, 0); audiomanager.setRouting(2, 11, 15);` – Jaiprakash Soni Jul 11 '11 at 02:50
0

This code is working for me to record outgoing phone calls,so please check it Here

Community
  • 1
  • 1
Mukesh Parmar
  • 941
  • 1
  • 15
  • 25
0

It seems that you cannot record a call from the API. One common workaround is to engage the speakerphone and record from the microphone - on many devices, the microphone will pick up the speaker adequately with this arrangement.

Another workaround is to do the recording on a telephony service somewhere and route calls through it.

rjmunro
  • 27,203
  • 20
  • 110
  • 132