【发布时间】:2018-05-18 07:04:17
【问题描述】:
我有一个应用程序,它记录传入和传出的语音呼叫,它在带有棉花糖或更高版本的设备上运行良好。但是当我尝试在 android 5.1.1 上运行它时,它给了我错误并且应用程序停止响应。
The error shown in logcat is-ava.lang.RuntimeException: Unable to start service com.android.hitech.calls.Unused.MyRecordingService@2cb0b090 with Intent { cmp=com.android.hitech.calls/.Unused.MyRecordingService (has extras) }: java.lang.IllegalStateException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2925)
at android.app.ActivityThread.access$2100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by: java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
at com.android.hitech.calls.Unused.MyRecordingService.onStartCommand(MyRecordingservice.java:88)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2908)
我录制语音通话的代码是-
recorder = new MediaRecorder();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
System.out.println("Present in MIC");
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
} else {
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALLS);
}
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
recorder.setOnErrorListener(this);
recorder.setOnInfoListener(this);
try {
recorder.prepare();
recorder.start();
} catch (IOException e) {
e.printStackTrace();
}
编辑-我按照下面答案中的建议做了,但我的错误仍然存在。现在通过稍微调整代码只调用一次调用状态,但应用程序仍然崩溃,甚至异常是相同的。
【问题讨论】:
标签: android mediarecorder android-5.1.1-lollipop internal-storage call-recording