Android ProximityAlert 在退出应用程序后不会保持活动状态(即按主页按钮)
我可以设置接近警报(即,当手机进入/退出指定半径时生成通知),只有当我仍然有应用程序时,它才能按我想要的方式工作。当我单击主页时,通常触发警报的半径退出/进入条件不会导致通知。
我很确定它与注册和取消注册接收者有关,但我无法弄清楚。当我不包含对 unregisterReceiver 的调用并按主页时,会出现泄漏接收器错误。当我将其包含在 onPause() 中并单击主页时,我没有收到任何错误,但警报不起作用。
我对这些接近警报有什么不明白的地方吗?让应用程序按照我的意愿响应接近度的最佳方式是什么?
I am able to set a proximity alert (i.e. generates a notification when the phone enters/exits specified radius) which works as I want only when I still have the app up. When I click home, the radius exit/enter conditions which normally fire the alert do not result in a notification.
I am pretty sure it has something to do with registering and unregister receivers, but I cannot figure it out. When I don't include a call to unregisterReceiver and press home, a leaked receiver error appears. When I include it in onPause() and click home, I get no errors, but the alert doesn't work.
Is there something I am not understanding about these proximity alerts? What is the best way to have an app respond to proximity as I wish it to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注册挂起的意图而不是接收者。他们在应用程序关闭后仍能幸存
Register pending intent instead of receiver. They survive application shutdown
在清单文件中注册您的广播接收器。它会自动注册和注销自己。
即使按下主页按钮后它也会起作用。
Register your BroadcastReceiver in the Manifest file. It will automatically register and unregister itself.
It will work even after the home button is pressed.