[英]Android ProximityAlert does not stay active after exiting app (i.e. pressing home button)
I am able to set a proximity alert (ie 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. 当我不包含对unregisterReceiver的呼叫并按home键时,会出现泄漏的接收器错误。 When I include it in onPause() and click home, I get no errors, but the alert doesn't work. 当我将其包含在onPause()中并单击“主页”时,我没有收到任何错误,但警报不起作用。
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? 让应用程序按我希望的方式响应距离的最佳方法是什么?
Register your BroadcastReceiver in the Manifest file. 在清单文件中注册您的BroadcastReceiver。 It will automatically register and unregister itself. 它将自动注册和注销自己。
<receiver android:name="ProximityIntentReceiver">
<intent-filter>
<action android:name="com.example.googlemaps.PROXIMITY_ALERT">
</intent-filter>
</receiver>
It will work even after the home button is pressed. 即使按下主页按钮,它也将起作用。
Register pending intent instead of receiver. 注册挂起的意图,而不是接收者。 They survive application shutdown 它们在应用程序关闭后仍能生存
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.