I\'m attempting to use AudioRecord
with AudioSource.VOICE_DOWNLINK
on Nexus 5X, Android 7.1 (my own build from AOSP).
I\'m already past the per
Not sure if it is a Nexus 5 specific issue but usually the class used to record calls is MediaRecorder
. Have you tried to replace AudioRecorder
by a MediaRecorder
?
Based on this stack-overflow question, I think you could try the following code based on Ben blog post:
import android.media.MediaRecorder;
import android.os.Environment;
import java.io.File;
import java.io.IOException;
public class CallRecorder {
final MediaRecorder recorder = new MediaRecorder();
final String path;
/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public CallRecorder(String path) {
this.path = sanitizePath(path);
}
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
/**
* Starts a new recording.
*/
public void start() throws IOException {
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(path).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.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
}
/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}
}
In this sample, I've used MediaRecorder.AudioSource.VOICE_CALL
but you can test other options like MediaRecorder.AudioSource.VOICE_COMMUNICATION
and also the microphone just to see if there are any hardware issues on your phone.