Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on Call Recording Android Application & facing issue in  application, when i'm recording call only speaker voice is recording but Incomming voice is not recording, i already changed all setting of audio format but facing same issue,
If anyone worked on call recording android application , kindly help me. 
Thanks...!


What I have tried:

Here is code.


public class RecordingService extends Service {
    private MediaRecorder rec;
    private boolean recoderstarted;
    private File file;
    String path = "sdcard/alarms/";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        //return super.onStartCommand(intent, flags, startId);

        file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        Date date = new Date();
        String stringDate = DateFormat.getDateTimeInstance().format(date);
        rec = new MediaRecorder();
        rec.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
        rec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        rec.setOutputFile(file.getAbsoluteFile() + "/" + stringDate + "callrec.3gp");
        rec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE);
        manager.listen(new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                super.onCallStateChanged(state, incomingNumber);
                if (TelephonyManager.CALL_STATE_IDLE == state ){
                    try {
                        if (rec == null) {
                            rec.stop();
                            rec.reset();
                            rec.release();
                            recoderstarted = false;
                            rec = null;
                            stopSelf();
                            Toast.makeText(getApplicationContext(),"Recording Stop.",Toast.LENGTH_SHORT).show();
                           
                        } else {
                            rec.stop();
                            rec.reset();
                            rec.release();
                            recoderstarted = false;
                            rec = null;
                            stopSelf();
                            Toast.makeText(getApplicationContext(),"Recording Stop.",Toast.LENGTH_SHORT).show();
                           
                        }
                    }
                    catch(Exception e) {
                        e.printStackTrace();
                    }
                }
                else if(TelephonyManager.CALL_STATE_OFFHOOK==state){
                    try {
                        file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
                        Date date = new Date();
                        String stringDate = DateFormat.getDateTimeInstance().format(date);
                        rec = new MediaRecorder();
                        rec.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
                        rec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                        rec.setOutputFile(file.getAbsoluteFile() + "/" + stringDate + "callrec.3gp");
                        rec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                        TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE);
                    rec.prepare();
                    rec.start();
                    recoderstarted=true;
                        Toast.makeText(getApplicationContext(),"Recording Start.",Toast.LENGTH_SHORT).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }


            }
        }, PhoneStateListener.LISTEN_CALL_STATE);

        return START_STICKY;
    }
}
Posted
Updated 12-Feb-18 19:05pm
v3
Comments
David Crow 8-Feb-18 11:04am    
While not a solution to your problem, I did run across this. The interesting part was, "Most of these apps rely solely on your microphone to record both incoming and outgoing audio." Maybe this will help point you in a better direction.

Here is another link I found. It looks more promising.
Usama Wajid 9-Feb-18 5:53am    
Then how to increase microphone volume while recording?
David Crow 9-Feb-18 9:02am    
Does AudioManager.adjustVolume() help?

1 solution

Have you tried increasing the volume
audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
 audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);


Also, check here[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900