【问题标题】:when handleGeofenceTransition() gets called in geofence example?当在地理围栏示例中调用 handleGeofenceTransition() 时?
【发布时间】:2013-07-04 05:18:46
【问题描述】:
我正在开发今年在 google I/OI 中发布的 android 地理围栏应用程序,它正在将用户当前位置 lat-lon 传递给具有不同半径(如 2、5、10、50 等)的地理围栏,但我无法收到通知.我不知道是什么问题,但logcat显示geofence已成功添加,它没有启动Intent服务,也没有调用handleGeofenceTransition()。
【问题讨论】:
标签:
android
location
google-play-services
geofencing
android-geofence
【解决方案1】:
如果您希望您的应用程序在发生转换时采取行动,您可以向前广播它,就像谷歌地理围栏示例处理错误一样。
简单的添加:
broadcastIntent.putExtra(
GeofenceUtils.EXTRA_GEOFENCE_TRANSITION_TYPE,
transition).putExtra(
GeofenceUtils.EXTRA_GEOFENCE_IDS_ARRAY,
Arrays.toString(geofenceIds))
.setAction(GeofenceUtils.ACTION_GEOFENCE_TRANSITION);
// Broadcast *locally* to other components in this app
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
您当然需要在接收类中添加代码处理意图