我使用的代码监测地理围栏过渡下面Android的地理栅栏上没有错误,但
LocationServices.GeofencingApi
.addGeofences(AssistApplication.getApiHelper().getClient(),
getGeofencingRequest(),
getPendingIntent(context,
GeofenceTransitionIntentService.class))
.setResultCallback(this);
没有GEOFENCE_TRANSITION_标志进入/退出触发这是我如何建立GeofencingRequest
private GeofencingRequest getGeofencingRequest()
{
return new GeofencingRequest.Builder()
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER |
GeofencingRequest.INITIAL_TRIGGER_EXIT)
.addGeofence(getGeofence())
.build();
}
private Geofence getGeofence()
{
return new Geofence.Builder()
.setRequestId(requestId)
.setCircularRegion(latitude, longitude, 100)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
Geofence.GEOFENCE_TRANSITION_EXIT)
.build();
}
地理栅栏触发正确的进入和退出,但是当我使用getGeofenceTransition()
,我没有得到任何这三个GEOFENCE_TRANSITION_
标志。
protected void onHandleIntent(Intent intent)
{
final GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event.hasError())
{
Log.e(TAG, getErrorMessage(event.getErrorCode()));
return;
}
switch (event.getGeofenceTransition())
{
case Geofence.GEOFENCE_TRANSITION_EXIT:
// Not triggered
break;
case Geofence.GEOFENCE_TRANSITION_ENTER:
case Geofence.GEOFENCE_TRANSITION_DWELL:
// Not triggered
break;
default:
// Triggered on exit and enter
}
}
请告知我是缺少在这里
你在你的'GeofencingRequest.Builder'设置?你从getGeofenceTransition()返回了什么?如果它是-1,那么你的意图不是来自转换警报。您的地理围栏事件是否在广播接收器中收到? – SimonH
我在构建请求的地方添加了代码。我设置'INITIAL_TRIGGER_ENTER'和'INITIAL_TRIGGER_EXIT'初始触发和'GEOFENCE_TRANSITION_ENTER'和'GEOFENCE_TRANSITION_EXIT'过渡。我没有得到任何'GEOFENCE_TRANSITION_'标志,所以根据API参考它必须是-1,但我知道它是没有错误触发的,因为当我输入/退出区域时执行'default'代码。如果它不是转换警报并且没有错误,那么触发该服务的是什么?我没有使用任何广播接收器只有'IntentService' –