background_task 0.0.8 background_task: ^0.0.8 copied to clipboard
Can be processed using location updates after the application transitions to the background.
background_task #
Motivation #
Enable developers to continue processing even when the application transitions to the background, we have created a package that allows processing to continue using location updates.This package was created with reference to background_location.
Can be used when you want to run the program periodically in the background.
- Monitor and notify the distance walked and steps.
- Notification of destination arrival.
Usage #
// Monitor notifications of background processes.
BackgroundTask.instance.stream.listen((event) {
// Implement the process you want to run in the background.
// ex) Check health data.
});
// Start background processing with location updates.
// Android only: Start Foreground service. If you want to show foreground service notifications, please execute a notification permission request before start.
await BackgroundTask.instance.start();
// Stop background processing and location updates.
await BackgroundTask.instance.stop();
Recommended to use with permission_handler.
final status = Platform.isIOS
? await Permission.locationAlways.request()
: await Permission.location.request();
if (!status.isGranted) {
return;
}
await BackgroundTask.instance.start();
Setup #
pubspec.yaml
dependencies:
background_task:
iOS: Info.plist
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Used to monitor location in the background and notify to app.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Used to monitor location in the background and notify to app.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Used to monitor location in the background and notify to app.</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
</array>
Android: AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>