gpt4 book ai didi

android - addProximityAlert 和 BroadcastReceivers

转载 作者:行者123 更新时间:2023-11-29 18:11:23 27 4
gpt4 key购买 nike

我目前正在开发一个内置了兴趣点的 map 应用程序。这些点应该通过接近警报触发器通知给用户。这是我正在使用的 addproximityAlert() 代码

loc.addProximityAlert(lat, longe, radius, -1, PendingIntent.getActivity(
c, 0, new Intent().putExtra(loc_name, loc_name), flag));

这个想法是,一旦警报触发,就会弹出一个警报对话框,其中包含有关该站点的简短信息,并提供关闭警报或获取更多信息(使用 WebView)的选项。

到目前为止,我没有出现运行时或编译时错误,但是当我访问每个站点时,没有任何反应。

我关于为什么什么都没有发生的理论也是;

1) 我没有正确使用 PendingIntent,或者

2) 我没有正确设置 BroadcastReceiver

这是 BroadcastRecevier 的 XML 代码,

<receiver android:name=".ProxyAlertReceiver" >
<intent-filter>
<action android:name="entering" />
</intent-filter>
</receiver>

我目前解决此问题的计划是修改 PendingIntent 以使用这样的新 Intent;

...new Intent(myContext, ProxyAlertReceiver.class)...

看看我是否得到任何结果。

非常感谢对我的问题的意见和建议!

最佳答案

您尝试过 PendingIntent.getBroadcast(...) 吗?

Intent locationReachedIntent = new Intent("entering");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1234,
locationReachedIntent, 0);

locationManager.addProximityAlert(longitude, latitude, radius, -1, pendingIntent);

我的应用程序中有上述代码。

关于android - addProximityAlert 和 BroadcastReceivers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10457628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com