flutter_background_service
flutter_background_service copied to clipboard
Can Geolocator run with this plugin at the background?
Can Geolocator run with this plugin at the background?
Did you try to use it with geolocator? I look at the geolocator plugin code, and for me, it should work. That plugin is ActivityAware, so you should just request required location permissions when app is in foreground, and then the plugin itself should work even if app is in background, when the plugin is not attached to any activity.
I am not sure, but maybe you will have to wait until the permission are granted before you start using geolocator in service, or try to init foreground service only when all the permissions are granted.
EDIT. I could be mistaken. Android 10+ requires service to have type location in android manifest, if it wants to access location. This plugin does not have service type filled, so you probably won't be able to access location in background mode on android 10+.
I tested this today, and i can confirm it works like i said - you can start foreground service, get locations updates when app is in foreground, but the moment you minimize it - location updates stop, because service is not marked with location type in android manifest in plugin package, and therefore is not able to access location.
@ekasetiawans
Maybe we should extend the android manifest to contain all service types like:
But by default service would start without any type?
I am not sure though if there is no problem with marking service as foreground serivce in android manifest and starting it as background service.
@incloudss looks like it's starting to be needed on android 10 and up, unfortunately i only have a device with android 9 and no problem regarding location on foreground service.
I am using geolocator package and it work fine in the background
I'm using it, works perfectly.
I am using geolocator package and it work fine in the background I'm using it, works perfectly.
Hello, could you share an example of how to implement, thanks
@byblady
Depending on your usage, I'd recommend using BackgroundLocator instead. However, if your use case needs Geolocator for some reason, use it in combination with Flutter Background Service.
Follow the documentation, it is easy to implement. If you still need help afterwards, ping me again.
Note: after implementation, you might get a few non-fatal execptions when you quit to background. Ignore them, I don't know why the exceptions show, but the library and the functions I needed still worked.
Hello. I'm trying to implement both flutter_background_service and geolocator but not able to. I have followed closely the example code and include this part to fetch location periodically in the onStart function but I keep getting the Missing Pluggin Exception, method getCurrentLocation is not implemented on channel. The same codes work well if I implement it to fetch location on button press. I have tried flutter clean and flutter run and that didn't help either. Any idea how I can work with both plugins?
Timer.periodic(const Duration(seconds: 30), (timer) async {
var position = await Geolocator.getCurrentPosition(
forceAndroidLocationManager: true,
desiredAccuracy: LocationAccuracy.high,
);
service.invoke('updateLocation', position as Map<String, dynamic>);
});
Hello. I'm trying to implement both flutter_background_service and geolocator but not able to. I have followed closely the example code and include this part to fetch location periodically in the onStart function but I keep getting the Missing Pluggin Exception, method getCurrentLocation is not implemented on channel. The same codes work well if I implement it to fetch location on button press. I have tried flutter clean and flutter run and that didn't help either. Any idea how I can work with both plugins?
Timer.periodic(const Duration(seconds: 30), (timer) async { var position = await Geolocator.getCurrentPosition( forceAndroidLocationManager: true, desiredAccuracy: LocationAccuracy.high, ); service.invoke('updateLocation', position as Map<String, dynamic>); });
same with me missing plugine exception