• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How can I release the mic after my app used it?

Adrianarx

Lurker
Hi,

Our app uses the mic to make calls. When a call starts the microphone is activated and the green icon on the top of the screen shows up showing it’s being used. When the call ends, the green icon keeps on the screen and I can’t use the mic on other apps.
We use the AudioManager to handle audio focus. https://developer.android.com/reference/android/media/AudioManager I can’t find in Google’s documentation how to release the microphone.
 
To release the microphone after a call ends, you can use the AudioManager.setMicrophoneMute() method to turn off the microphone. This method takes a boolean parameter that specifies whether the microphone should be muted or not.

Here is an example of how you can use this method to release the microphone after a call ends:

Code:
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMicrophoneMute(true); // turn off the microphone

Alternatively, you can use the AudioManager.abandonAudioFocus() method to abandon audio focus and allow other audio apps to use the microphone. This method takes an AudioManager.OnAudioFocusChangeListener as a parameter, which can be used to detect when audio focus is lost or regained.

Here is an example of how you can use this method to release the microphone after a call ends:

Code:
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.abandonAudioFocus(new AudioManager.OnAudioFocusChangeListener() {
    @Override
    public void onAudioFocusChange(int focusChange) {
        // handle audio focus changes here
    }
});
 
Back
Top Bottom