此方法位于服务类中,并且在选择呼叫时从广播接收器调用服务类(TelephonyManager.EXTRA_STATE_OFFHOOK)
private void startRecording() throws IOException {
if (!isRecording) {
this.isRecording = true;
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
try {
recorder.prepare();
} catch (Exception e) {
e.printStackTrace();
}
recorder.start();
}
}