I have implemented an Android background service (based in Pocket Sphinx) that continuously listens, detects and spots certain keywords when the phone's screen is on, and then reacts accordingly (for a domotic project). However, my app should always have a lower priority and I want it to release the microphone's resources when any other app needs to use it. Is there any system intent or system broadcast that I can receive when an app -wants- to use the microphone (so that my service can release it)? Or, is there a better approach or better practice?
This is the log with the errors I want to avoid when another app wants to access the microphone:
AudioFocus requestAudioFocus() from android.media.AudioManager@419c3908com.google.android.voicesearch.a.h@419c67b8
I/MicrophoneInputStream(32360): mic_starting com.google.android.speech.audio.w@41989a30
D/AudioHardwareALSA(277): openInputStream: devices 0x400000 format 0x1 channels 16 sampleRate 16000
E/AudioHardwareALSA(277): error:Input stream already opened for recording
E/AudioRecord(32360): Could not get audio input for record source 6
E/AudioRecord-JNI(32360): Error creating AudioRecord instance: initialization check failed.
E/AudioRecord-Java(32360): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.
E/MicrophoneInputStream(32360): Failed to initialize AudioRecord