Android 地理围栏:调试器显示Geofence的值。Geofence_TRANSITION_ENTER等于0

Android 地理围栏:调试器显示Geofence的值。Geofence_TRANSITION_ENTER等于0,android,android-geofence,android-debug,Android,Android Geofence,Android Debug,我正在尝试在我的应用程序中实现地理围栏,但我不明白为什么调试器显示geofinence.geofinence_TRANSITION_ENTER的值等于0 下面是我手头的内容。如果我理解正确,那么如果设备已经在地理围栏内,那么 geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER 应该为true,因为调试器显示geofenceTransition的值为1,但由于geofeen.geofeen_TRANSITION_ENTER等于0(??

我正在尝试在我的应用程序中实现地理围栏,但我不明白为什么调试器显示geofinence.geofinence_TRANSITION_ENTER的值等于0

下面是我手头的内容。如果我理解正确,那么如果设备已经在地理围栏内,那么

geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER
应该为true,因为调试器显示geofenceTransition的值为1,但由于geofeen.geofeen_TRANSITION_ENTER等于0(??),因此不会执行if块。我正在MI Redmi android设备上测试。任何帮助都将不胜感激

@Override
protected void onHandleIntent(Intent intent) {

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        Log.e(TAG, "Error in geofencing event");
        return;
    }

    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {

        Toast.makeText(this,"Entered geofence",Toast.LENGTH_LONG).show();
    } else {
        // Log the error.
        Toast.makeText(this,"Not entered",Toast.LENGTH_LONG).show();
        Log.e(TAG, String.valueOf(geofenceTransition));
    }

}

我敢肯定,一年多之后,你要么已经解决了这个问题,要么放弃了,转而从事房地产开发

当然,查看com.google.android.gms.location code,
geofinence.geofinence\u TRANSITION\u ENTER
是一个常量,设置为1

因此,要么你误读了一些东西,旧版本的com.google.android.gms.location代码有一个bug,要么不平等就在别处

此问题的唯一其他原因是,在创建
GeofencingRequest
时没有设置初始触发器

GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
如果您错误地设置了触发器(即初始触发退出),那么您的意图处理程序将只针对该触发器触发,因此
If(geofenceTransition==Geofence.Geofence\u TRANSITION\u ENTER)
将永远不会为真