使用 android 在 fencing 中没有收到任何通知

not getting any notification in fencing using android

我正在尝试 运行 android 中的击剑样本。我在 google 地图上显示了一个半径为 2 米的栅栏,同时我显示了我当前位置的半径为 2 米。

正如您在下图中看到的,我的当前位置(绿色)远离围栏(红色),但我的 Geofence.GEOFENCE_TRANSITION_EXITIntentService 仍然没有被调用。

即使我进入围栏也没有任何通知。

我看过其他线程,但没有任何效果。

这是我的基本设置

<service
            android:name=".GeofenceTransitionsIntentService"
            android:exported="false"
          >
        </service>

待定意向

 private PendingIntent getGeofenceTransitionPendingIntent() {
        Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
        return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

onConnected 内部

mGeofenceRequestIntent = getGeofenceTransitionPendingIntent();

LocationServices.GeofencingApi.addGeofences(mApiClient, mGeofenceList,
                mGeofenceRequestIntent);

我用 BroadcastReceiver 试过了,但没有成功

 private PendingIntent getmGeofenceTransitionPendingIntentReceiver(){

        if(mGeofenceRequestIntent!=null){

            return mGeofenceRequestIntent;
        }else{


            Intent intent = new Intent(GEOFENCE_RECEIVER);
            return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        }
    }

在我的清单文件中

<receiver android:name=".GeofenceReceiver"  android:exported="false">
            <intent-filter>
                <action android:name="com.geofence.georeceiver"/>
            </intent-filter>
</receiver>

您当前的半径应小于地理围栏的半径。 ENTERED 事件仅在您的整个 "radius circle" 位于地理围栏内时触发。

另外2m的地理围栏很小,我建议至少±10m。