做安卓的录音功能代码如下:
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
File audioFile = null;
try {
audioFile = File.createTempFile("record_369" , ".amr");
} catch (IOException e) {
e.printStackTrace();
}
mediaRecorder.setOutputFile(audioFile.getAbsolutePath());
try {
mediaRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaRecorder.start();
一直会报 java.lang.RuntimeException: setAudioSource failed. 异常
而且添加了权限 <uses-permission android:name="android.permission.RECORD_AUDIO"/>
请问这是怎么回事啊?
http://blog.csdn.net/lissdy/article/details/7039332
API 23及以上的话,需要在代码中使用动态权限申请,