I am following the examples, I init the service, check for permissions and then call the foreground service with the callback as in the examples. The call returns false without throwing any error.
//outside of class
// The callback function should always be a top-level function.
@pragma('vm:entry-point')
void startCallback() {
print('starting callback');
// The setTaskHandler function must be called to handle the task in the background.
FlutterForegroundTask.setTaskHandler(FirstTaskHandler());
}
FlutterForegroundTask.init(
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'foreground_service',
channelName: 'Foreground Service',
channelDescription:
'This notification appears when the foreground service is running.',
channelImportance: NotificationChannelImportance.LOW,
priority: NotificationPriority.LOW,
iconData: NotificationIconData(
resType: ResourceType.mipmap,
resPrefix: ResourcePrefix.ic,
name: 'launcher',
),
),
iosNotificationOptions: const IOSNotificationOptions(
showNotification: true,
playSound: false,
),
foregroundTaskOptions: const ForegroundTaskOptions(
interval: 5000,
autoRunOnBoot: true,
allowWifiLock: true,
),
);
print('attempting to start service');
try {
bool started = await FlutterForegroundTask.startService(
notificationTitle: 'Foreground service is running',
notificationText: 'Tap to return to the app',
callback: startCallback,
);
print(started);
} catch (e) {
print(e.toString());
}
I am following the examples, I init the service, check for permissions and then call the foreground service with the callback as in the examples. The call returns false without throwing any error.