PhoneStateListener onCellLocationChanged does not get called in background
I've implemented a sticky-service which runs in the background. I want my app to handle gsm-Cell-changes. But my PhoneStateListener does not get called reliably. Sometimes it just gets called after i pressed a button and the phone resumes from sleep mode. How am i able to force the phone开发者_运维问答 to recognize gsm-Locationchanges reliably in a background service? Why does it sometimes work and other times not?
Put PhoneStateListener
in the service and then put the requests for listening in the onStartCommand
. If the service stops listening for the changes, try to create a Timer
that calls for a TimerTask
class inside the service which contains the listening requests and make the Timer
call for the TimerTask
class every X milliseconds. That worked for me.
精彩评论