Closed ramazancopur closed 6 months ago
Show me an example of what you wish to do using code.
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.
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.
"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?
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).
How will I perform this operation when the application is killed? Can you help with an example code?
For iOS, what you have is fine. For Android, see api docs Config.enableHeadless.
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?
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.
I want to learn this for iOS.
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.
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?
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”.
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.