I'm developing an app that lets the user store and listen to voice messages and I want to change the audio output source when the user brings the phone up to his ear.
I tried working with the SensorManager
but I found out that Samsung devices have problematic proximity sensors (I have a Galaxy S10e). After a bit of research I found that the best option is using the PROXIMITY_SCREEN_OFF_WAKE_LOCK
and now the screen turns off and on when I bring the phone to and from my ear (which is a good thing). However, using the wake lock doesn't call onResume()
or onPause()
nor does it send ACTION_SCREEN_ON
or ACTION_SCREEN_OFF
broadcasts.
Is there anyway to listen to the PROXIMITY_SCREEN_OFF_WAKE_LOCK
activity so I could know when to change the audio output source?
Thanks in advance :)
If anyone stumbles upon this post.
My solution was registering a SenseorEventListener
and acquiring a PROXIMITY_SCREEN_OFF_WAKE_LOCK
wake lock.
Apparently if a wake lock is acquired the proximity sensor works fine :)