How do I stop hogging the microphone How do I stop hogging the microphone android android

How do I stop hogging the microphone


This is tricky, as I'm not a ware of any API for this. This surely will require system-level APIs to work like an "Ok Google" type of thing.

A viable option would be (from https://stackoverflow.com/a/43623308/603270) to run a Job at regular intervals, checking for foreground apps using android.permission.PACKAGE_USAGE_STATS.

This might suffice. But you could also add things regarding phone calls (how to detect phone call broadcast receiver in android) using android.intent.action.PHONE_STATE or media playback (via Receiver or maybe even MediaPlayer directly).


If you're really wanting to get this thing working, an alternative would be to get an array list of all installed apps on the system and which ones require permission to use the mic or not, then use an accessibility service to monitor the users screen if an app the user just opened requires the mic (which you'll know from the array you just grabbed). From there, disable the mic in your app if their app needs the mic. The background service can then check in intervals of, say, two minutes, to see if the app that required the mic is still open. This is really inefficient. But if you don't care, then this might be a good option.


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.