Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record Call in Android 2.2

I have written this code for recording Calls. It works fine in Android 2.1. In Android 2.2, it creates an output file with 0 bytes.

How I can solve this?

MediaRecorder _recorder = new MediaRecorder();


public void start() throws IOException {
    try {
        String state = android.os.Environment.getExternalStorageState();
        if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
            throw new IOException("SD Card is not mounted.  It is " + state
                    + ".");
        }

        // make sure the directory we plan to store the recording in exists
        File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/sam.wav").getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            throw new IOException("Path to file could not be created.");
        }


        _recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL );
        _recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        _recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/test.wav");
        _recorder.prepare();
        _recorder.start();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
like image 938
Kartik Bhatt Avatar asked Jul 27 '11 03:07

Kartik Bhatt


People also ask

Can I record a phone call on my Android?

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

Is Android 11 support call recording?

However, not every one of the tools to record calls on android will give the best outcomes. If you want to record your Android calls, the speediest and least complex strategy is to utilize the best call recorder android 11. Answer the call, tap the Record button and your phone will deal with the rest.

Where is call record in Android 11?

You can access the recording under the Recents section of the the Phone app. Tap the name of the caller you recorded, select the recording from the list of calls, and then tap Play.


2 Answers

Use this snippet

_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK 
| MediaRecorder.AudioSource.VOICE_UPLINK );

instead of

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);
like image 133
Nikunj Avatar answered Nov 02 '22 03:11

Nikunj


Call recording only works on some Android phones. It might work on one phone running 2.1, but not on a different model running 2.2. Although the API will compile and run on all architectures, some devices have disabled this feature in the hardware.

See How can I record voice and record Call in Android? for more details.

like image 31
David Avatar answered Nov 02 '22 04:11

David