Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Get Notified when the current Mode inside AudioManager gets changed

In Android I need to get notified when the current audio mode gets changed.

I can get this value through getMode() but this is polling.

I don't want to poll every few seconds.

What are my options?

(Please note that I'm not asking about ringerMode)

like image 223
Hagai L Avatar asked Feb 01 '16 10:02

Hagai L


1 Answers

You can use AudioFocus for devices running Android OS version 2.2 and higher, preassuming your app is also playing audio.

You can register for audio focus changes and then listen onAudioFocusChange(int focusChange) method. By this way you will be notified of audio mode changes as well as other audio focus changes. I hope this helps.

You can also use PhoneStateListener to listen phone states changes and corresponding audio modes.

like image 163
CanC Avatar answered Sep 19 '22 02:09

CanC