You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flutter info (flutter doctor):
[√] Flutter (Channel stable, v1.9.1+hotfix.5, on Microsoft Windows [Version 10.0.18362.418], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.39.2)
Save location to firebase using the provided url to cloud function on ActivityChange event when app is already killed.
Context
I was following this issue but it didn't solve it for me.
Basically i want to log data to server only on activity change. I have the following code:
Future<Null> _initPlatformState() async {
bg.BackgroundGeolocation.onActivityChange(_onActivityChange);
bg.BackgroundGeolocation.ready(
bg.Config(
locationAuthorizationRequest:"Always",
reset:false,
debug:true,
logLevel: bg.Config.LOG_LEVEL_VERBOSE,
desiredAccuracy: bg.Config.DESIRED_ACCURACY_LOWEST,
distanceFilter:1000.0,
stopOnTerminate:false,
enableHeadless:true,
startOnBoot:true,
stopTimeout:1,
autoSync:false,
foregroundService:true,
),
).then((bg.State state) {
print('[ready] ${state.toMap()}');
if (state.schedule.isNotEmpty) {
bg.BackgroundGeolocation.startSchedule();
}
}).catchError((error) {
print('[ready] ERROR: $error');
});
}
Future<void> _logToServer(Map<String, dynamic> data) async {
Dio()
.post(
// the url to the cloud firebase functionFlavorConfig.instance.values.locationUrl,
data: data,
)
.then((Response response) {
print('[data posted on ${DateTime.now()}] ${response.statusCode}');
}).catchError((e) {
print(e);
});
}
void_onActivityChange(bg.ActivityChangeEvent event) async {
print('[${bg.Event.ACTIVITYCHANGE}] - $event');
if (_activity != event.activity) {
_activity = event.activity;
bg.BackgroundGeolocation.getCurrentPosition(
persist:false, // <-- do not persist this location
desiredAccuracy:40, // <-- desire an accuracy of 40 meters or less
maximumAge:10000, // <-- Up to 10s old is fine.
timeout:30, // <-- wait 30s before giving up.
samples:1, // <-- sample just 1 location
).then((bg.Location location) async {
Map<String, dynamic> data = {
"activity": event.activity,
"timestamp": location.timestamp,
"userId": _userId,
"userEmail": _userEmail,
"longitude": location.coords.longitude,
"latitude": location.coords.latitude,
"uuid": location.uuid,
};
await_logToServer(data);
}).catchError((error) {
print("Error while fetching location: $error");
});
}
}
It works fine as long as app is not killed, and when app is killed the debug sounds are played but the function is not executed. Nothing is printed in the logs on firebase. A headless task isn't working when i call the method in it.
I'm hoping you can point me in the right direction.
The text was updated successfully, but these errors were encountered:
Your Environment
flutter doctor
):[√] Flutter (Channel stable, v1.9.1+hotfix.5, on Microsoft Windows [Version 10.0.18362.418], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.39.2)
Expected Behavior
Save location to firebase using the provided url to cloud function on ActivityChange event when app is already killed.
Context
I was following this issue but it didn't solve it for me.
Basically i want to log data to server only on activity change. I have the following code:
It works fine as long as app is not killed, and when app is killed the debug sounds are played but the function is not executed. Nothing is printed in the logs on firebase. A headless task isn't working when i call the method in it.
I'm hoping you can point me in the right direction.
The text was updated successfully, but these errors were encountered: