Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3271928
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:46:32+00:00 2026-05-17T18:46:32+00:00

I am trying out the record outgoing call using mic written this code but

  • 0

I am trying out the record outgoing call using mic written this code but not working, I tested the code for simple audio record it works fine, I am not sure when to start media record I putted start in broadcast receiver may be problem is there.

Here Audiorecoder is another class is created where I have implemented MediaRecoder

public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        audrec = new AudioRecorder("newcall");
        this.context = context;
        if (intent.getAction().equalsIgnoreCase(Intent.ACTION_DIAL)) 
        {
            try {
                audrec.start();
                recordstarted = 1;
                telManager= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

            } catch (IOException e) {
                // TODO Auto-generated catch block
                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)
            {
                try {
                    audrec.stop();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                recordstarted =0;
            }
            break;
        }
        case TelephonyManager.CALL_STATE_OFFHOOK:
        {
            try {
                audrec.start();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            recordstarted =1;
            break;
        }
        case TelephonyManager.CALL_STATE_RINGING:       
        {
            try {
                audrec.start();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            recordstarted =1;
            break;
        }
        }
    }   

Another Code that i am trying out that create 3Gp file but not playing

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class androidrec extends Activity
{
   Button btn_start;
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState); setContentView(R.layout.main);
      btn_start = (Button) findViewById(R.id.btn_start);
      UpdateRecorderState();
      btn_start.setOnClickListener(new View.OnClickListener() 
      {
         public void onClick(View v) 
         {              
            //          Toast.makeText(getBaseContext(),"Please enter both phone number and message.", 
            //          Toast.LENGTH_SHORT).show();
            if(!SharedData._Started) { StartServicesAtStartUp.Start_CallRec(getBaseContext()); }
            else { StartServicesAtStartUp.Stop_CallRec(getBaseContext()); }
            UpdateRecorderState();
         }
      });        


   }

   private void UpdateRecorderState() 
   {
      if(SharedData._Started)
      {btn_start.setText("Stop Recording");}
      else
      {btn_start.setText("Start Recording");}
   }
}[/code]


import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.media.MediaRecorder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

//import com.lumitrend.netlogger.Logger;

public class CallStateListener extends PhoneStateListener {
   public void onCallStateChanged(int state, String incomingNumber)
   {
      super.onCallStateChanged(state, incomingNumber);
      switch(state)
      {
      case TelephonyManager.CALL_STATE_IDLE:
         if(SharedData._Recording) 
         { Recorders_Stop(); }
         break;
      case TelephonyManager.CALL_STATE_RINGING:
         break;
      case TelephonyManager.CALL_STATE_OFFHOOK:
         String CallDate = SanityDate();
         String CallNum = SanityNum(incomingNumber);
         String RootDir = SharedData._Path ;  
         String CallDir = SharedData._Path + CallNum + "/" ;
         String CallFile = SharedData._Path +  CallNum + "/" + CallNum + CallDate ;
         if(!SharedData._Recording)
         {
            SharedData._Recording = true;
            String med_state = android.os.Environment.getExternalStorageState();
            if(!med_state.equals(android.os.Environment.MEDIA_MOUNTED))
            { break; }

            File directory = null;
            directory = new File(RootDir + "text.txt" ).getParentFile();
            if (!directory.exists() && !directory.mkdirs())
            { break; }

            directory = new File(CallDir + "text.txt" ).getParentFile();
            if (!directory.exists() && !directory.mkdirs())
            { break; }

            Recoders_Init(CallFile);
            Recorder_Prepare();
         }
         Log.v("DEBUG", TelephonyManager.CALL_STATE_OFFHOOK + " ITS.CallRecorder - Recording Started " + state);
         break;
      }
   }

   private String SanityDate() {
      SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd-HHmmss");
      Date currentTime_1 = new Date();
      return formatter.format(currentTime_1);
   }

   private void Recorders_Stop() {
      try { 
         SharedData._recorder.stop(); SharedData._recorder.reset();
         //SharedData._recorder_down.stop(); SharedData._recorder_down.reset();
         //SharedData._recorder_up.stop();       SharedData._recorder_up.reset(); 
      }
      catch (IllegalStateException e) {}
      SharedData._Recording = false;
   }

   private void Recorder_Prepare() {
      try {
         SharedData._recorder.prepare(); SharedData._recorder.start(); 
         //SharedData._recorder_down.prepare(); SharedData._recorder_down.start(); 
         //SharedData._recorder_up.prepare(); SharedData._recorder_up.start(); 
      }
      catch (IllegalStateException e) { e.printStackTrace(); }
      catch (IOException e) { e.printStackTrace(); }
   }

   private void Recoders_Init(String path) {
      String _ext = ".3gp";
      int out_format = MediaRecorder.OutputFormat.THREE_GPP;

      SharedData._recorder.setAudioSource(SharedData._Rec_Type);
      SharedData._recorder.setOutputFormat(out_format);
      SharedData._recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      SharedData._recorder.setOutputFile(path + "both" + _ext);

      /*
                SharedData._recorder_down.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);
                SharedData._recorder_down.setOutputFormat(out_format);
                SharedData._recorder_down.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                SharedData._recorder_down.setOutputFile(path + "-down" + _ext);

                SharedData._recorder_up.setAudioSource(MediaRecorder.AudioSource.VOICE_UPLINK);
                SharedData._recorder_up.setOutputFormat(out_format);
                SharedData._recorder_up.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                SharedData._recorder_up.setOutputFile(path  + "-up" + _ext);
       */

   }
   private String SanityNum(String numstr)
   {
      String out = "";
      for(char ch : numstr.toCharArray())
      {
         switch(ch)
         {
         case ' ': 
            break;
         case '~': 
            break;
         case '!': 
            break;
         case '@': 
            break;
         case '#': 
            break;
         case '$': 
            break;
         case '%': 
            break;
         case '^': 
            break;
         case '&': 
            break;
         case '*': 
            break;
         case '(': 
            break;
         case ')': 
            break;
         case '-': 
            break;
         case '_': 
            break;
         case '=': 
            break;
         case '|': 
            break;
         default:
            out = out + ch;
         }
      }
      return out;
   }
} 


import android.media.MediaRecorder;

final public class SharedData
{

   static int _Rec_Type = android.media.MediaRecorder.AudioSource.VOICE_CALL;


   static String _Path = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/ITS-CallRecorder/";
   static boolean _Started = false;
   static boolean _AutoStart = true;
   static boolean _Recording = false;

   static MediaRecorder _recorder = new MediaRecorder();
   static MediaRecorder _recorder_down = new MediaRecorder();
   static MediaRecorder _recorder_up = new MediaRecorder();

   SharedData() {    }
}

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;



public class StartServicesAtStartUp extends BroadcastReceiver
{
   public static Intent phoneStateListener;
   public void onReceive(Context context, Intent intent)
   {
      Log.d("DEBUG", "com.its.CallRecorder Initiated ...");
      Start_CallRec(context);
   }

   public static void Start_CallRec(Context context)
   {
      if(!SharedData._Started )
      {
         if(SharedData._AutoStart)
         {
            phoneStateListener = new Intent(context, CallStateListener.class);
            phoneStateListener.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startService(phoneStateListener);
            Log.d("DEBUG", "com.its.CallRecorder Call Recorder Started ...");
            TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            CallStateListener callStateListener = new CallStateListener();
            tManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);
            SharedData._Started = true;
            Toast.makeText(context," Call Recording Started ... ", Toast.LENGTH_SHORT).show();
         }       
      }
      else
      {
         Toast.makeText(context," Call Recording Already Active.. ", Toast.LENGTH_SHORT).show();
      }
   }

   public static void Stop_CallRec(Context context)
   {
      if(SharedData._Started )
      {
         context.stopService(phoneStateListener);
         Toast.makeText(context," Call Recording Stopped  ... ", Toast.LENGTH_SHORT).show();
         SharedData._Started = false;                    
      }
      else
      {
         Toast.makeText(context," Call Recording Already Stopped  ... ",  Toast.LENGTH_SHORT).show();
      }
   }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:46:33+00:00Added an answer on May 17, 2026 at 6:46 pm

    Call recording is not yet possible on Android. See this feature request.

    You can record your voice from microphone, but you can not record the sound of the other party. If you only want to record your voice use android.media.MediaRecorder.AudioSource.MIC

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select a record out of the table1 by joining table2
I'm trying to figure out the best way to insert a record into a
I'm trying to allow users to vote a record up/down with Ajax. I'm using
I'm currently trying out db4o (the java version) and I pretty much like what
I'm trying out the following query: SELECT A,B,C FROM table WHERE field LIKE 'query%'
I am trying out the debugger built into Zend studio . It seems great!
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
I'm thinking about trying out MVC later today for a new app we're starting
I'm trying out Linq for the first time and having a bit of difficult
I have been trying out the NameValueDeserializer from MVCContrib, which will take a IList

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.