Android上的AudioRecord不能用于marshmallow。错误表示未初始化的AudioRecord

时间:2016-03-14 10:20:38

标签: android audiorecord

我已尝试过stackoverflow中的其他解决方案,但没有一个对我有用。我拥有指定的所有权限。此应用程序适用于除Marshmallow之外的其他设备。

这是日志

03-14 13:17:53.742 5427-5427/com.radiobox.vigilantevoice E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.radiobox.vigilantevoice, PID: 5427
                                                                       java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                           at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
                                                                           at android.view.View.performClick(View.java:5198)
                                                                           at android.view.View$PerformClick.run(View.java:21147)
                                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:148)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                        Caused by: java.lang.reflect.InvocationTargetException
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
                                                                           at android.view.View.performClick(View.java:5198) 
                                                                           at android.view.View$PerformClick.run(View.java:21147) 
                                                                           at android.os.Handler.handleCallback(Handler.java:739) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                           at android.os.Looper.loop(Looper.java:148) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                        Caused by: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
                                                                           at android.media.AudioRecord.startRecording(AudioRecord.java:885)
                                                                           at com.radiobox.vigilantevoice.VoiceActivity.plays(VoiceActivity.java:130)
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at android.view.View$DeclaredOnClickListener.onClick(View.java:4447) 
                                                                           at android.view.View.performClick(View.java:5198) 
                                                                           at android.view.View$PerformClick.run(View.java:21147) 
                                                                           at android.os.Handler.handleCallback(Handler.java:739) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                           at android.os.Looper.loop(Looper.java:148) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

1 个答案:

答案 0 :(得分:0)

Android引入了运行时权限,需要为权限编写额外的代码。用户在运行应用程序时会被要求提供权限。有一些开源库可以轻松实现运行时权限。我个人认为this有帮助。