android - 在 Google 的地理围栏教程中看不到地理围栏过渡

标签 android location geofencing android-geofence

我正在尝试使用 Google's example: Creating & Monitoring Geofences 测试地理围栏功能.我已经上传了 code here .

问题是我从来没有收到进入或退出的通知。我有 Wifi、4G 和 GPS。我尝试通过以下方式进行测试:

  1. 我什至走出家门大约 50 英尺,然后又走回去——但没有收到任何通知。我可以看到播放服务已连接,甚至是 "GeofenceUtils.ACTION_GEOFENCES_ADDED in MainActivity.java"被触发,所以我认为地理围栏已正确添加。
  2. 在设置中启用模拟位置并使用此 Fake GPS App并更改了位置 - 从与 Geofence1 相同的坐标开始,然后设置为完全在外部(在另一个状态)的东西 - 但我仍然没有收到退出通知。

我做错了什么? A任何人都成功运行了这个Google's example: Creating & Monitoring Geofences .我已经上传了 code here便于浏览。

我只是想学习地理围栏 - 检测进入和退出。 我会将任何答案标记为正确答案,我可以使用它来让地理围栏在我的真实设备上工作

I enter the coordinates and radius below .

最佳答案

我也遇到了示例代码的问题。我遇到的主要问题之一是关于声明 ReceiveTransitionsIntentService。您不需要添加 BroadcastReceiver 或请求位置更新,但您需要更改 AndroidManifest 以将导出的值设置为 true,如下所示:

<service
    android:name=".ReceiveTransitionsIntentService"
    android:exported="true" >
</service>

确保服务的路径也是正确的。

我已经大大简化了 Google 示例,您可以找到代码和解释 here .我已经删除了 UI 组件和持久性地理围栏存储,因此这个示例应该更容易理解。希望这对您有所帮助!

关于android - 在 Google 的地理围栏教程中看不到地理围栏过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22905144/

相关文章:

c# - 以 xamarin 形式获取设备的经纬度位置

ios - 如何在我的应用程序 View 中显示 map ?

iOS Geofence CLCircularRegion 监控。位置管理器 :didExitRegion does not seem to work as expected

java - Google 搜索应用在 Android 中发送通知 'at this shop?'

android - 使用新的 Android API 跟踪 100 多个同步地理围栏

java - 登录后添加 header 拦截器 - Retrofit

android - 在 Windows 7 上的 Eclipse 中调试 Genymotion

android - 无法解决 github 存储库

android - 如何在 Android 中为 Vpn 断开连接添加额外的处理?

javascript - 该网站如何更改网站位置?