我正在使用Google的位置服务示例(即地理围栏示例)进行测试。 https://github.com/android/location-samples/tree/master/Geofencing
据我所知,用户应该在位置关闭上发生地理围栏事件,因此我可以处理状态GEOFENCE_NOT_AVAILABLE,但是位置设置被关闭我没有收到任何事件,并且我一般不会看到任何错误。关闭位置信息后如何获取事件
使用示例,您应该能够在GeofenceBroadcastReceiver.java中拦截状态代码。
public class GeofenceBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent)
if ( event.hasError() && event.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE ) { ... }
}
}
如果仍然不确定,请查看下面的GeofencingEvent.getErrorCode()链接。https://developers.google.com/android/reference/com/google/android/gms/location/GeofencingEvent.html#getErrorCode()