transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
648 stars 239 forks source link

Check service is running or not? #1272

Closed urvashi-k-7span closed 6 months ago

urvashi-k-7span commented 7 months ago

Is there any way to check that service is already running or not like I can see the log ⚠️ #ready already called. Redirecting to #setConfig I am calling below things in initState

bg.BackgroundGeolocation.onLocation(_onLocation, _onLocationError);
    bg.BackgroundGeolocation.onMotionChange(_onMotionChange);
    bg.BackgroundGeolocation.onActivityChange(_onActivityChange);
    bg.BackgroundGeolocation.onProviderChange(_onProviderChange);
    bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);
    bg.BackgroundGeolocation.onHttp(_onHttp);
    bg.BackgroundGeolocation.onAuthorization(_onAuthorization);

    ////
    // 2.  Configure the plugin
    //
    await bg.BackgroundGeolocation.ready(
      bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
        distanceFilter: 50,
        stopOnTerminate: false,
        startOnBoot: true,
        debug: false,
        enableHeadless: true,
        autoSync: true,
        autoSyncThreshold: 5,
        batchSync: true,
        maxBatchSize: 50,
        locationsOrderDirection: 'ASC',
        maxDaysToPersist: 30,
        pausesLocationUpdatesAutomatically: false,
        // activityRecognitionInterval: 10000,
        backgroundPermissionRationale: bg.PermissionRationale(
          title: "Allow {applicationName} to access this device's location even when the app is closed or not in use.",
          message: 'This app collects location data to enable recording your trips to work and calculate distance-travelled.',
          positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
          negativeAction: 'Cancel',
        ),
        logLevel: bg.Config.LOG_LEVEL_VERBOSE,
        url: 'https://abc-api.preview.im/api/v1/client/locations',
        headers: {
          'X-Requested-With': 'XMLHttpRequest',
          'Authorization': 'Bearer $token',
        },
      ),
    ).then((bg.State state) async {
      log('[ready] ${state.toMap()}');
      if (!state.enabled) {
        ////
        // 3.  Start the plugin.
        //

        await bg.BackgroundGeolocation.start();
        // await bg.BackgroundGeolocation.sync();
      }
    }).catchError((error) {
      log('[ready] ERROR: $error');
    });
christocracy commented 7 months ago

Are you getting that warning while hot-reloading during development? If that’s the case, you don’t need to worry about it.