transistorsoft / flutter_background_geolocation

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

How can I send a different value to my server? #1239

Closed ramazancopur closed 6 months ago

ramazancopur commented 6 months ago

It lacks a fixed value, and what I intend to transmit as an additional parameter is the sound status of the phone. Sending HTTP requests to my server suffices without the necessity to store them in the database. If you inform me about this, I would like to buy your package.

christocracy commented 6 months ago

Show me an example of what you wish to do using code.

ramazancopur commented 6 months ago

The capability to transmit diverse values, like the variable phone sound status, alongside the location parameter to my server. These values are not constant; they can fluctuate.

christocracy commented 6 months ago

I do t know what "phone sound status" is exactly, but presumably there is some api for it that allows setting up an event-listener for when it changes. When it changes, use the plug-in's .setConfig method to apply it to Config.extras, an arbitrary key/value {} applied to each recorded location.

There is no way to dynamically append data to each location.

ramazancopur commented 6 months ago

"device's current sound mode" example: Normal, Silent & Vibrate mode

// To modify config after #ready has been executed, use #setConfig BackgroundGeolocation.setConfig(Config( params: { "sound_mode": 1 }, )).then((State state) { BackgroundGeolocation.sync(); });

Will this be effective?

christocracy commented 6 months ago

Learn how to syntax highlight "fenced codeblocks".

Yes, you can use Config.params (attached to params of http request) or Config.extras (attached to each location {} with http data).

ramazancopur commented 6 months ago

How will I perform this operation when the application is killed? Can you help with an example code?

christocracy commented 6 months ago

For iOS, what you have is fine. For Android, see api docs Config.enableHeadless.

ramazancopur commented 1 month ago

When the application is closed, in which event listener should I perform setConfig?

I am currently doing it like this.

BackgroundGeolocation.onHttp((HttpEvent response) async {
        // ignore: avoid_print
        print(
            '[http] success? ${response.success}, status? ${response.status}');

        Logger.debug(
          "Istek Gönderilme durumu ${response.responseText},${response.status}",
        );

        await setGeofence();

        var ringerValue = await Codes.getRingerMode();

        var state = await bg.BackgroundGeolocation.setConfig(bg.Config(
          locationTemplate:
              '{"lat": <%= latitude %>,"long": <%= longitude %>,"sarj": <%= battery.level %>,"hiz": <%= speed %>,"sesdurum": $ringerValue,"isCharging": <%= battery.is_charging %>,"isMoving": <%= is_moving %>,"mock": <%= mock %>,"activity": "<%= activity.type %>"}',
          geofenceTemplate:
              '{"geofenceId": "<%= geofence.identifier %>","geofenceAction": "<%= geofence.action %>" ,"lat": <%= latitude %>,"long": <%= longitude %>,"sarj": <%= battery.level %>,"hiz": <%= speed %>,"sesdurum": $ringerValue,"isCharging": <%= battery.is_charging %>,"isMoving": <%= is_moving %>,"mock": <%= mock %>,"activity": "<%= activity.type %>"}',
        ));

        print('setconfig $state -- ${state.url}');

        bg.Logger.debug(
            'setConfigden sonra ki statetir $state -- ${state.url}');
      });

I have thoroughly reviewed the documents but couldn't find the answer. Can you help me?

christocracy commented 1 month ago

When the application is closed, in which event listener should I perform setConfig?

It’s completely different for iOS vs Android and you didn’t specify which.

ramazancopur commented 1 month ago

I want to learn this for iOS.

christocracy commented 1 month ago

For iOS, read the api docs Config.stopOnTerminate.

The only thing that will re-awaken a terminated iOS app is to move at least 200 meters.

ramazancopur commented 1 month ago

I have read the document you mentioned. Can I implement it in the 'onLocation' listener, for example? Will the setConfig operation occur when the application is closed?

christocracy commented 1 month ago

Will the setConfig operation occur when the application is closed?

When iOS relaunches a terminated app after the device moves about 200 meters, your app is no longer terminated. This is all easily tested in the iOS simulator with location simulated with “Freeway Drive”.

IMG_1874