PhoneStateListener onCellLocationChanged 不会在后台调用
我已经实现了一个在后台运行的粘性服务。我希望我的应用程序能够处理 gsm-Cell-changes。但我的 PhoneStateListener 没有被可靠地调用。有时,在我按下按钮并且手机从睡眠模式恢复后,它就会被呼叫。 我如何才能强制手机在后台服务中可靠地识别 gsm-位置更改?为什么有时有效有时无效?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
PhoneStateListener
放入服务中,然后将监听请求放入onStartCommand
中。如果服务停止侦听更改,请尝试创建一个Timer
来调用包含侦听请求的服务内的TimerTask
类,并使Timer< /code> 每 X 毫秒调用
TimerTask
类。这对我有用。Put
PhoneStateListener
in the service and then put the requests for listening in theonStartCommand
. If the service stops listening for the changes, try to create aTimer
that calls for aTimerTask
class inside the service which contains the listening requests and make theTimer
call for theTimerTask
class every X milliseconds. That worked for me.