Unable to access microphone when another app is using it in Android

ぐ巨炮叔叔 提交于 2019-11-30 16:57:16

问题


I'm using code from the following URL in order to get sound data from the microphone with AudioRecord: http://www.dreamincode.net/forums/topic/303235-visualizing-sound-from-the-microphone/

The problem I'm seeing is that if another app is also using the microphone, I'm getting an error (status -3) from AudioRecord. Everything works as expected if I kill the other app which is using the microphone. Is there an elegant solution to allow my app to access the microphone even if another app is already using it?

Thank you.


回答1:


Sadly, only one app at a time can access the microphone (just like the camera).

Also, there is no standard way to inform another app that you want access to the microphone (so that they release the resources and let you access it). You could however send a broadcast to all other apps ("requesting the microphone"), but the other apps would have to implement this feature (and very few or zero developers will do this).

I would recommend you to simply inform the user that the microphone is currently not available, because you can't do anything else.




回答2:


If you are using the "OK Google" function with the option to access it from any page, try turning that off (the 'any page' bit From Google app screen MENU>SETTINGS>VOICE>"OK GOOGLE DETECTION">FROM ANY SCREEN=OFF): it hijacks the microphone, or can do.



来源:https://stackoverflow.com/questions/24170124/unable-to-access-microphone-when-another-app-is-using-it-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!