简体   繁体   中英

Record phone calls on android phone?

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..

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.

  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

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);

该代码对我有用 ,可以记录去电 ,请在此处检查

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM