Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 352
codeman Avatar asked Jun 11 '14 18:06

codeman


People also ask

Can't access microphone Another app is using it Android?

Go to Settings>Apps>App Permissions, then Microphone, and see which apps have permission for the mic.

Can two apps use mic at the same time?

When two apps are capturing concurrently, only one app receives audio and the other gets silence. Android shares the input audio according to these rules: If neither app is privacy-sensitive, the app with a UI on top receives audio. If neither app has a UI, the one that started capture the most recently receives audio.


2 Answers

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.

like image 96
Manuel Allenspach Avatar answered Sep 18 '22 22:09

Manuel Allenspach


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.

like image 30
Sean Waters Avatar answered Sep 19 '22 22:09

Sean Waters