Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record phone calls on android phone?

Tags:

java

android

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

like image 970
Mobile_Application_Developer Avatar asked Jul 30 '10 09:07

Mobile_Application_Developer


People also ask

Is it possible to record a mobile Phone call?

On your Android device, open the Phone app . Call recording. Under 'Always record', turn on Numbers not in your contacts. Tap Always record.


2 Answers

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.

like image 188
Sojan P R Avatar answered Sep 24 '22 13:09

Sojan P R


  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
like image 43
CommonsWare Avatar answered Sep 23 '22 13:09

CommonsWare