首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Geofence在进入/退出时触发,没有错误,但没有GEOFENCE_TRANSITION_标志

Android Geofence在进入/退出时触发,没有错误,但没有GEOFENCE_TRANSITION_标志
EN

Stack Overflow用户
提问于 2017-01-05 17:47:17
回答 0查看 1.5K关注 0票数 2

我正在使用下面的代码监视geofence转换

代码语言:javascript
复制
LocationServices.GeofencingApi
    .addGeofences(AssistApplication.getApiHelper().getClient(),
                  getGeofencingRequest(),
                  getPendingIntent(context,  
                              GeofenceTransitionIntentService.class))
    .setResultCallback(this);

这就是我构建GeofencingRequest的方法

代码语言:javascript
复制
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();
}

Geofence在进入和退出时正确触发,但是当我使用getGeofenceTransition()时,我得不到三个GEOFENCE_TRANSITION_标志中的任何一个。

代码语言:javascript
复制
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
    }
}

请告诉我这里遗漏了什么

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41481717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档