I am trying to record the call when phone call is accepted in android.
For that I have created a Receiver
, in that I have kept code for MediaRecorder
initial setup like this..
onReceive(){
recorder = new MediaRecorder();
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/myrecording"+System.currentTimeMillis()+".3gp";
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(outputFile);
}
and in the phoneState change listener, for the case OFF_HOOK
case TelephonyManager.CALL_STATE_OFFHOOK: {
Log.v(TAG,"call state is OffHook");
try{
recorder.prepare();
Thread.sleep(1000);
recorder.start();
} catch(Exception e) {
Log.e(TAG,"Error occured here");
}
break;
}
every time when the control comes into this state I am getting error saying that
E/MediaRecorder(23056): start failed: -2147483648
W/System.err(23056): java.lang.RuntimeException: start failed.
I tried this but it is also not working, could you please help me in this.Thanks