我已经开始搜索它,但没有找到任何解决方案
我正在录制来电和去电
代码适用于拨出电话,但在来电时提供例外
recorder = new MediaRecorder();
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/OK");
dir.mkdirs();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/OK/"+"yes"+".3gpp");
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
Log.d("illegal",e.toString());
} catch (IOException e) {
Log.d("io",e.toString());
}
logcat的
02-23 01:43:08.346 11231-11231/com.example.myapps.acr **I/record﹕ start**
02-23 01:43:08.426 11231-11231/com.example.myapps.acr **E/MediaRecorder﹕ start failed: -38**
02-23 01:43:08.426 11231-11231/com.example.myapps.acr **D/illegal﹕ java.lang.IllegalStateException**
请帮助解决为什么它不接听来电..
答案 0 :(得分:1)
recorder.prepare();
Thread.sleep(1000);
recorder.start();
对于来电,需要时间准备。
保持准备1秒钟,一切正常。