My app needs to know early on at onCreate() whether the headset is plugged in or not (if it isn't, it should simply display a dialog and exit, as this is a headset-only app, not to be used with a speaker).
Because registering a receiver for ACTION_HEADSET_PLUG or ACTION_AUDIO_BECOMING_NOISY is recommended to be done in either onStart() or onResume(), relying on these messages in onCreate is out of question.
So, I turned instead to Audio Manager's isSpeakerphoneOn() with the hope that my app's onCreate() will find it reflecting the correct status of the speakerphone.
Unfortunately however, isSpeakerphoneOn() always return false
, despite the speakerphone being on and nothing else plugged in (neither wired nor bluetooth headset).
My questions are:
Why? What are the conditions for this isSpeakerphoneOn() method to correctly reflect the phone's status?
- Is there a way to determine in onCreate() whether the headset is plugged in or not?