颤音背景地理位置包不起作用

发布于 2025-02-11 20:33:27 字数 14218 浏览 1 评论 0原文

我正在使用Flutter_background_geolocation软件包跟踪用户位置并监视地理事件。我使其能够在无头模式下工作,并在用户进入或退出受监视的地理林时向用户显示通知。

问题是,每当我运行应用程序并更改其位置时,该软件包都不会向我显示有关位置或Geofence更新的任何日志。无论应用在前景或背景如何,都会发生这种情况。 _onlocation()也不是 _ongeoefence()被触发。

这是我的代码:

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);
  static const String id = "HomeScreen";

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  bg.Config backgroundGeolocationConfig = bg.Config(
    // fastestLocationUpdateInterval: 0, // 120000 seconds =2 minutes
    showsBackgroundLocationIndicator: true,
    // locationUpdateInterval: 30000, //30 seconds
    notification: bg.Notification(
        title: "Accessing your location",
        text: "Remote clocking app is accessing your location"),
    locationAuthorizationRequest: 'Always',
    locationAuthorizationAlert: {
      'titleWhenNotEnabled': 'Location-services are not enabled',
      'titleWhenOff': 'Location-services are OFF',
      'instructions': "You must enable 'Always' in location-services",
      'cancelButton': 'Cancel',
      'settingsButton': 'Settings'
    },
    foregroundService: true,
    allowIdenticalLocations: true,
    minimumActivityRecognitionConfidence: 10,
    disableLocationAuthorizationAlert: false,
    forceReloadOnGeofence: true,
    backgroundPermissionRationale: bg.PermissionRationale(
        title:
        "Allow Remote Clocking App to access this device's location even when the app is closed or not in use.",
        message:
        "This app collects location data to enable you to clock in/out from your work.",
        positiveAction: "Change to Allow all the time",
        negativeAction: "Cancel"),
    enableHeadless: true,
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    geofenceProximityRadius: 1000, //todo: minimum is 1K
    geofenceModeHighAccuracy:
    true, // With the default `geofenceModeHighAccuracy: false`, a device will have to move farther *into* a geofence before the *ENTER* event fires and farther *out of* a geofence before the *EXIT* event fires.
    isMoving: true,
    // stopTimeout:
    //     60, //specifies the number of minutes to wait before turning off location-services and transitioning to *stationary* state after the ActivityRecognition System detects the device is `STILL`.  An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light.
    stopTimeout:
    15, //specifies the number of minutes to wait before turning off location-services and transitioning to *stationary* state after the ActivityRecognition System detects the device is `STILL`.  An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light.
    stopOnTerminate:
    false, // Defaults to **`false`**.  Set **`true`** to engage background-tracking after the device reboots.
    startOnBoot: true,
    useSignificantChangesOnly: true,
    heartbeatInterval: 60,
    debug:
    false, //this parameter if true; will play sound for debugging the BackgroundGeolocation events
    reset:
    true, // <-- set true to ALWAYS apply supplied config; not just at first launch.
    logLevel: bg.Config.LOG_LEVEL_DEBUG,
  );
 @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getZonesPlusLastClocking();
    bg.BackgroundGeolocation.onLocation(_onLocation,
        _onLocationError); //Fired when user location changes  ==> Required to update latitude, longitude and accuracy
    bg.BackgroundGeolocation.onGeofence(
        _onGeofence); //Fired when crossing one of the monitored geofences
    // Fired whenever the plugin changes motion-state (stationary->moving and vice-versa)
    bg.BackgroundGeolocation.onProviderChange(
        _onProviderChange); //Fired whenever app is launched or location authorization changes
    // Listen to geofence events
    bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);
    // 2.  Configure the plugin
    bg.BackgroundGeolocation.ready(backgroundGeolocationConfig)
        .then((bg.State state) {
      getCurrentUserLocation();
      log("Called get current user location");
      setState(() {
        isLocationPermissionGranted = true;
      });
      // 3.  Start the plugin.
      log('[ready] BackgroundGeolocation is configured and ready to use');
      bg.BackgroundGeolocation.startGeofences().catchError((_) {
        log("Geofence tracking has already been started");
      }); //start tracking the geofences
    }).onError((error, stackTrace) async {
      setState(() {
        locationDescription = kGettingYourLocation;
      });
      showUnableToTrackYourLocationDialog(context);
    });
    UserPreferences().getUserName().then((value) {
      setState(() {
        userDisplayName = value;
        dateTime = getFormattedDateTime();
        time = getTimeIn12HrsFormat(DateTime.now());
      });
    });
    Timer.periodic(const Duration(seconds: 1),
        (Timer t) => _getCurrentTime()); //update current time
    Timer.periodic(const Duration(days: 1),
        (Timer t) => _getCurrentDate()); //update current date
    updateClockingHistory();
    // bg.Logger.getLog(bg.SQLQuery(start: DateTime.now(), limit: 100));
  }
void _onConnectivityChange(
      bg.ConnectivityChangeEvent connectivityChangeEvent) {
    if (connectivityChangeEvent.connected == false) {
      log("2");
      showNoWifiDialog(context);
    } else {
      getZonesPlusLastClocking();
    }
    log("Internet connectivity is set to: ${connectivityChangeEvent.connected}");
  }

  void _onGeofence(bg.GeofenceEvent event) {
    log('[on geofence] ' + event.toString());
    String geofenceName =
        event.identifier.substring(0, event.identifier.indexOf("-"));
    if (event.action == 'ENTER' || event.action == 'DWELL') {
      //update locationDescription upon geofence entry
      setState(() {
        locationDescription = geofenceName;
        zoneId = event.extras![kZoneId];
      });
      print(
          "From onGeofence()---on enter or Dwell-- zoneId: ${event.extras![kZoneId].toString()}");
      if ((lastClocking == null || lastClocking!.type.compareTo('OUT') == 0) &&
          event.action == 'ENTER') {
        NotificationService.showNotification(
          title: 'You have entered $geofenceName',
          body: "Do you want to clock in?",
        );
      }
    } else if (event.action == 'EXIT') {
      //update locationDescription upon geofence exit
      setState(() {
        locationDescription = kNotAllowedLocation;
        log("zoneID:  ${event.extras![kZoneId]}");
        zoneId = event.extras![kZoneId];
      });
      print(
          "From onGeofence()---on exit-- zoneId: ${event.extras![kZoneId].toString()}");

      //if there is a network connectivity and last clocking was in,; clock user out
      if (isConnectedToInternet() &&
          lastClocking != null &&
          lastClocking!.type.compareTo("IN") == 0 &&
          zoneId != -1) {
        RemoteClockingServices.submitClocking(
                latitude: latitude,
                longitude: longitude,
                zoneId: zoneId,
                enforceClockOut: true)
            .then((bool isSubmitted) async {
          log("Value of isSubmitted is $isSubmitted");
          if (isSubmitted) {
            log("onGeofence exit");
            userAction = kClockOut;
            log("User has been clocked out");
            setState(() {
              clockInTime = getTimeIn12HrsFormat(lastClocking!.time);
              clockInDescription = kClockIn.toUpperCase();
              clockOutTime = time;
              clockOutDescription = "CLOCK OUT";
              log("clock out time is updated");
            });
            //stop the timer
            log("Freeze the timer");
            _stopWatchTimer.onExecute.add(StopWatchExecute.stop);
            await getZonesPlusLastClocking(); //required to update the last clocking object to the clocked out time
            NotificationService.showNotification(
              title: 'You were clocked out by the system',
              body:
                  "You were clocked out since you have exited from $geofenceName",
            );
            setState(() {
              zoneId = -1;
            });
            print(
                "From onGeofence()---on exit- after enforce clock out -- zoneID: ${event.extras![kZoneId].toString()}");
          } else {
            //else submission did not succeed
            NotificationService.showNotification(
              title: 'Action Required',
              body:
                  "Kindly clock out manually, you are not permitted to remain clocked in since you have left $geofenceName",
            );
          }
        });
      }
    }
  }

  void _onLocation(bg.Location location) {
    setState(() {
      log("from onLocation setState $time");
      latitude = location.coords.latitude;
      longitude = location.coords.longitude;
      accuracy = location.coords.accuracy;
    });
  }

  void _onLocationError(bg.LocationError error) {
    log('[onLocation] ERROR: $error');
    if (error.code == 408) {
      log("[onLocation] error: LOCATION TIMEOUT $error");
    }
  }

  void _onProviderChange(bg.ProviderChangeEvent event) {
    log('[onProviderChange: $event');
    switch (event.status) {
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_DENIED:
        // Android & iOS
        log('- Location authorization denied');
        bg.BackgroundGeolocation.requestPermission().then((value) {
          if (value == 0) {
            setState(() {
              isLocationPermissionGranted = true;
              log("- Location authorization granted value= $value");
            });
          } else {
            setState(() {
              isLocationPermissionGranted = false;
              log("- Location authorization denied, value = $value");
            });
          }
        }).catchError((error) {
          log("requestPermission() error: " + error.toString());
        });
        break;
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_ALWAYS:
        // Android & iOS
        log('- Location always granted');
        setState(() {
          isLocationPermissionGranted = true;
        });
        break;
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_WHEN_IN_USE:
        // iOS only
        log('- Location WhenInUse granted');
        setState(() {
          isLocationPermissionGranted = true;
        });
        break;
    }
  }
  bool isConnectedToInternet() {
    bool isConnected = true;
    bg.BackgroundGeolocation.providerState.then((value) {
      if (value.network == false) {
        isConnected = false;
      }
    });
    return isConnected;
  }

Future<void> getZonesPlusLastClocking() async {
    if (isConnectedToInternet()) {
      //get the status response from the API
      Map<String, dynamic> statusResponse =
          await RemoteClockingServices.getStatusData();
      log("Called getStatusData()");
      log("Response: $statusResponse");
      //populate the temporary variables
      print(statusResponse[kAllowedZones] as List);
      List<AllowedZone> zonesTemp = (statusResponse[kAllowedZones] as List)
          .map((zone) => AllowedZone.fromJson(zone as Map<String, dynamic>))
          .toList();
      log("zonesTemp: ${zonesTemp.toString()}");
      Clocking? clockingTemp;
      if (statusResponse[kLastClocking] != null) {
        log("Last clocking is not null. converting json to clocking object");
        clockingTemp = Clocking.fromJson(
            statusResponse[kLastClocking] as Map<String, dynamic>);
      }
      //update the UI
      setState(() {
        log("AllowedZones are being updated");
        allowedZones = zonesTemp;
        if (allowedZones.isEmpty) {
          setState(() {
            locationDescription = kNotAllowedLocation;
          });
        }
        if (statusResponse[kLastClocking] != null) {
          log("updating lastClocking");
          lastClocking = clockingTemp;
        }
      });
      //todo: will the zones be changes over time? Can ?i just get them if the list is not empty
      List<bg.Geofence> geofences = [];
      bg.BackgroundGeolocation.geofences
          .then((List<bg.Geofence> monitoredGeofences) {
        if (monitoredGeofences.isEmpty) {
          for (int i = 0; i < allowedZones.length; i++) {
            // add geofence in for zone[i]
            geofences.add(bg.Geofence(
                identifier: "${allowedZones[i].zoneName}-in",
                radius: allowedZones[i].radius,
                latitude: allowedZones[i].latitude,
                longitude: allowedZones[i].longitude,
                notifyOnEntry: true,
                notifyOnExit: false,
                notifyOnDwell: true,
                extras: {
                  kZoneId: allowedZones[i].id
                })); //todo: notify on dwell to keep the screen updated with the identifier in case no access to the Internet
            //add geofence out for zone out
            geofences.add(bg.Geofence(
                identifier: "${allowedZones[i].zoneName}-out",
                radius: allowedZones[i].radiusOut,
                latitude: allowedZones[i].latitude,
                longitude: allowedZones[i].longitude,
                notifyOnEntry: false,
                notifyOnExit: true,
                notifyOnDwell: false,
                extras: {kZoneId: allowedZones[i].id}));
            log("${allowedZones[i].zoneName} was added to geofences");
          }
          bg.BackgroundGeolocation.addGeofences(geofences).then((bool success) {
            log('[addGeofences] success');
          }).catchError((dynamic error) {
            log('[addGeofences] FAILURE: $error');
          });
        }
      });
    }
  }
}

另一个问题是,当应用程序正在运行时,我总是会获取此日志。我不确定这是否是此问题的根本原因:

W/设置(6400):设置airplane_mode_on已从android.provider.settings.system转移到android.provider.settings.global,返回仅读取值。

如果有人可以研究我的问题并提出解决方案,我将不胜感激。

I am using flutter_background_geolocation package to track user location and monitor geofence events. I have enabled it to work in headless mode as well to show notifications to the user when he enters or exits a monitored geofence.

The issue is that whenever I run the app and change its location, the package is not showing me any logs about location or geofence update. This happens regardless of the app being in foreground or background. Neither _onLocation() nor
_onGeoefence() get triggered.

This is my code:

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);
  static const String id = "HomeScreen";

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  bg.Config backgroundGeolocationConfig = bg.Config(
    // fastestLocationUpdateInterval: 0, // 120000 seconds =2 minutes
    showsBackgroundLocationIndicator: true,
    // locationUpdateInterval: 30000, //30 seconds
    notification: bg.Notification(
        title: "Accessing your location",
        text: "Remote clocking app is accessing your location"),
    locationAuthorizationRequest: 'Always',
    locationAuthorizationAlert: {
      'titleWhenNotEnabled': 'Location-services are not enabled',
      'titleWhenOff': 'Location-services are OFF',
      'instructions': "You must enable 'Always' in location-services",
      'cancelButton': 'Cancel',
      'settingsButton': 'Settings'
    },
    foregroundService: true,
    allowIdenticalLocations: true,
    minimumActivityRecognitionConfidence: 10,
    disableLocationAuthorizationAlert: false,
    forceReloadOnGeofence: true,
    backgroundPermissionRationale: bg.PermissionRationale(
        title:
        "Allow Remote Clocking App to access this device's location even when the app is closed or not in use.",
        message:
        "This app collects location data to enable you to clock in/out from your work.",
        positiveAction: "Change to Allow all the time",
        negativeAction: "Cancel"),
    enableHeadless: true,
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    geofenceProximityRadius: 1000, //todo: minimum is 1K
    geofenceModeHighAccuracy:
    true, // With the default `geofenceModeHighAccuracy: false`, a device will have to move farther *into* a geofence before the *ENTER* event fires and farther *out of* a geofence before the *EXIT* event fires.
    isMoving: true,
    // stopTimeout:
    //     60, //specifies the number of minutes to wait before turning off location-services and transitioning to *stationary* state after the ActivityRecognition System detects the device is `STILL`.  An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light.
    stopTimeout:
    15, //specifies the number of minutes to wait before turning off location-services and transitioning to *stationary* state after the ActivityRecognition System detects the device is `STILL`.  An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light.
    stopOnTerminate:
    false, // Defaults to **`false`**.  Set **`true`** to engage background-tracking after the device reboots.
    startOnBoot: true,
    useSignificantChangesOnly: true,
    heartbeatInterval: 60,
    debug:
    false, //this parameter if true; will play sound for debugging the BackgroundGeolocation events
    reset:
    true, // <-- set true to ALWAYS apply supplied config; not just at first launch.
    logLevel: bg.Config.LOG_LEVEL_DEBUG,
  );
 @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getZonesPlusLastClocking();
    bg.BackgroundGeolocation.onLocation(_onLocation,
        _onLocationError); //Fired when user location changes  ==> Required to update latitude, longitude and accuracy
    bg.BackgroundGeolocation.onGeofence(
        _onGeofence); //Fired when crossing one of the monitored geofences
    // Fired whenever the plugin changes motion-state (stationary->moving and vice-versa)
    bg.BackgroundGeolocation.onProviderChange(
        _onProviderChange); //Fired whenever app is launched or location authorization changes
    // Listen to geofence events
    bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);
    // 2.  Configure the plugin
    bg.BackgroundGeolocation.ready(backgroundGeolocationConfig)
        .then((bg.State state) {
      getCurrentUserLocation();
      log("Called get current user location");
      setState(() {
        isLocationPermissionGranted = true;
      });
      // 3.  Start the plugin.
      log('[ready] BackgroundGeolocation is configured and ready to use');
      bg.BackgroundGeolocation.startGeofences().catchError((_) {
        log("Geofence tracking has already been started");
      }); //start tracking the geofences
    }).onError((error, stackTrace) async {
      setState(() {
        locationDescription = kGettingYourLocation;
      });
      showUnableToTrackYourLocationDialog(context);
    });
    UserPreferences().getUserName().then((value) {
      setState(() {
        userDisplayName = value;
        dateTime = getFormattedDateTime();
        time = getTimeIn12HrsFormat(DateTime.now());
      });
    });
    Timer.periodic(const Duration(seconds: 1),
        (Timer t) => _getCurrentTime()); //update current time
    Timer.periodic(const Duration(days: 1),
        (Timer t) => _getCurrentDate()); //update current date
    updateClockingHistory();
    // bg.Logger.getLog(bg.SQLQuery(start: DateTime.now(), limit: 100));
  }
void _onConnectivityChange(
      bg.ConnectivityChangeEvent connectivityChangeEvent) {
    if (connectivityChangeEvent.connected == false) {
      log("2");
      showNoWifiDialog(context);
    } else {
      getZonesPlusLastClocking();
    }
    log("Internet connectivity is set to: ${connectivityChangeEvent.connected}");
  }

  void _onGeofence(bg.GeofenceEvent event) {
    log('[on geofence] ' + event.toString());
    String geofenceName =
        event.identifier.substring(0, event.identifier.indexOf("-"));
    if (event.action == 'ENTER' || event.action == 'DWELL') {
      //update locationDescription upon geofence entry
      setState(() {
        locationDescription = geofenceName;
        zoneId = event.extras![kZoneId];
      });
      print(
          "From onGeofence()---on enter or Dwell-- zoneId: ${event.extras![kZoneId].toString()}");
      if ((lastClocking == null || lastClocking!.type.compareTo('OUT') == 0) &&
          event.action == 'ENTER') {
        NotificationService.showNotification(
          title: 'You have entered $geofenceName',
          body: "Do you want to clock in?",
        );
      }
    } else if (event.action == 'EXIT') {
      //update locationDescription upon geofence exit
      setState(() {
        locationDescription = kNotAllowedLocation;
        log("zoneID:  ${event.extras![kZoneId]}");
        zoneId = event.extras![kZoneId];
      });
      print(
          "From onGeofence()---on exit-- zoneId: ${event.extras![kZoneId].toString()}");

      //if there is a network connectivity and last clocking was in,; clock user out
      if (isConnectedToInternet() &&
          lastClocking != null &&
          lastClocking!.type.compareTo("IN") == 0 &&
          zoneId != -1) {
        RemoteClockingServices.submitClocking(
                latitude: latitude,
                longitude: longitude,
                zoneId: zoneId,
                enforceClockOut: true)
            .then((bool isSubmitted) async {
          log("Value of isSubmitted is $isSubmitted");
          if (isSubmitted) {
            log("onGeofence exit");
            userAction = kClockOut;
            log("User has been clocked out");
            setState(() {
              clockInTime = getTimeIn12HrsFormat(lastClocking!.time);
              clockInDescription = kClockIn.toUpperCase();
              clockOutTime = time;
              clockOutDescription = "CLOCK OUT";
              log("clock out time is updated");
            });
            //stop the timer
            log("Freeze the timer");
            _stopWatchTimer.onExecute.add(StopWatchExecute.stop);
            await getZonesPlusLastClocking(); //required to update the last clocking object to the clocked out time
            NotificationService.showNotification(
              title: 'You were clocked out by the system',
              body:
                  "You were clocked out since you have exited from $geofenceName",
            );
            setState(() {
              zoneId = -1;
            });
            print(
                "From onGeofence()---on exit- after enforce clock out -- zoneID: ${event.extras![kZoneId].toString()}");
          } else {
            //else submission did not succeed
            NotificationService.showNotification(
              title: 'Action Required',
              body:
                  "Kindly clock out manually, you are not permitted to remain clocked in since you have left $geofenceName",
            );
          }
        });
      }
    }
  }

  void _onLocation(bg.Location location) {
    setState(() {
      log("from onLocation setState $time");
      latitude = location.coords.latitude;
      longitude = location.coords.longitude;
      accuracy = location.coords.accuracy;
    });
  }

  void _onLocationError(bg.LocationError error) {
    log('[onLocation] ERROR: $error');
    if (error.code == 408) {
      log("[onLocation] error: LOCATION TIMEOUT $error");
    }
  }

  void _onProviderChange(bg.ProviderChangeEvent event) {
    log('[onProviderChange: $event');
    switch (event.status) {
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_DENIED:
        // Android & iOS
        log('- Location authorization denied');
        bg.BackgroundGeolocation.requestPermission().then((value) {
          if (value == 0) {
            setState(() {
              isLocationPermissionGranted = true;
              log("- Location authorization granted value= $value");
            });
          } else {
            setState(() {
              isLocationPermissionGranted = false;
              log("- Location authorization denied, value = $value");
            });
          }
        }).catchError((error) {
          log("requestPermission() error: " + error.toString());
        });
        break;
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_ALWAYS:
        // Android & iOS
        log('- Location always granted');
        setState(() {
          isLocationPermissionGranted = true;
        });
        break;
      case bg.ProviderChangeEvent.AUTHORIZATION_STATUS_WHEN_IN_USE:
        // iOS only
        log('- Location WhenInUse granted');
        setState(() {
          isLocationPermissionGranted = true;
        });
        break;
    }
  }
  bool isConnectedToInternet() {
    bool isConnected = true;
    bg.BackgroundGeolocation.providerState.then((value) {
      if (value.network == false) {
        isConnected = false;
      }
    });
    return isConnected;
  }

Future<void> getZonesPlusLastClocking() async {
    if (isConnectedToInternet()) {
      //get the status response from the API
      Map<String, dynamic> statusResponse =
          await RemoteClockingServices.getStatusData();
      log("Called getStatusData()");
      log("Response: $statusResponse");
      //populate the temporary variables
      print(statusResponse[kAllowedZones] as List);
      List<AllowedZone> zonesTemp = (statusResponse[kAllowedZones] as List)
          .map((zone) => AllowedZone.fromJson(zone as Map<String, dynamic>))
          .toList();
      log("zonesTemp: ${zonesTemp.toString()}");
      Clocking? clockingTemp;
      if (statusResponse[kLastClocking] != null) {
        log("Last clocking is not null. converting json to clocking object");
        clockingTemp = Clocking.fromJson(
            statusResponse[kLastClocking] as Map<String, dynamic>);
      }
      //update the UI
      setState(() {
        log("AllowedZones are being updated");
        allowedZones = zonesTemp;
        if (allowedZones.isEmpty) {
          setState(() {
            locationDescription = kNotAllowedLocation;
          });
        }
        if (statusResponse[kLastClocking] != null) {
          log("updating lastClocking");
          lastClocking = clockingTemp;
        }
      });
      //todo: will the zones be changes over time? Can ?i just get them if the list is not empty
      List<bg.Geofence> geofences = [];
      bg.BackgroundGeolocation.geofences
          .then((List<bg.Geofence> monitoredGeofences) {
        if (monitoredGeofences.isEmpty) {
          for (int i = 0; i < allowedZones.length; i++) {
            // add geofence in for zone[i]
            geofences.add(bg.Geofence(
                identifier: "${allowedZones[i].zoneName}-in",
                radius: allowedZones[i].radius,
                latitude: allowedZones[i].latitude,
                longitude: allowedZones[i].longitude,
                notifyOnEntry: true,
                notifyOnExit: false,
                notifyOnDwell: true,
                extras: {
                  kZoneId: allowedZones[i].id
                })); //todo: notify on dwell to keep the screen updated with the identifier in case no access to the Internet
            //add geofence out for zone out
            geofences.add(bg.Geofence(
                identifier: "${allowedZones[i].zoneName}-out",
                radius: allowedZones[i].radiusOut,
                latitude: allowedZones[i].latitude,
                longitude: allowedZones[i].longitude,
                notifyOnEntry: false,
                notifyOnExit: true,
                notifyOnDwell: false,
                extras: {kZoneId: allowedZones[i].id}));
            log("${allowedZones[i].zoneName} was added to geofences");
          }
          bg.BackgroundGeolocation.addGeofences(geofences).then((bool success) {
            log('[addGeofences] success');
          }).catchError((dynamic error) {
            log('[addGeofences] FAILURE: $error');
          });
        }
      });
    }
  }
}

Another issue is that I always get this log when the app is running. I am not sure if it is the root cause of this issue :

W/Settings( 6400): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.

I would appreciate it if anyone can look into my issue and suggest a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文