简体   繁体   中英

Listening to PROXIMITY_SCREEN_OFF_WAKE_LOCK

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM