I'm software engineer using Flutter in Japan.
Developing an alarm app that wakes me up in the morning, and having trouble implementing the following.
I would appreciate it if you could help me.
Question.
I would like to know if there is a way to execute a specific process at a scheduled time,
even if the app is killed or backGround.
Details.
I'm currently developing on an alarm app that sends local notifications & custom music at a specified time.
I was able to schedule local notifications to send at the specified time.
However, I can't find a way to run a specific process in the background at the same time.
(It's an image of a process that plays specific music selected by the user)
What I've found out
Confirmed that notifications can be sent on a specified day and at a specified time every week using flutter_local_notifications.
(execute flutterLocalNotificationsPlugin#zonedSchedule()
)
However, in flutter_local_notifications, there is no such thing as a listener to receive the notification itself.
(There is an onSelectNotification, but it doesn't work until user taps the notification bar.)
The library author says that there is no listener to fire such notification timing,
So I decided to use only local notifications in this library and look for another library to replace the background processing.
https://github.com/MaikuB/flutter_local_notifications/issues/1201
I found background_fetch and WorkManager to be particularly useful, but I gave up on using these libraries as well.
The reason is that with the above two libraries can only be executed in the sense of 15 minutes, as shown below, due to iOS limitations,
and I suspect that the process cannot be executed at the intended timing.
workManagaer
https://pub.dev/packages/workmanager#customisation-android-only
// Periodic task registration
Workmanager().registerPeriodicTask(
"2",
"simplePeriodicTask",
// When no frequency is provided the default 15 minutes is set.
// Minimum frequency is 15 min. Android will automatically change your frequency to 15 min if you have configured a lower frequency.
If you have configured a lower frequency. frequency: Duration(hours: 1),
)
background_fetch
Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period of background running-time. This plugin will execute your provided callbackFn whenever a background-fetch event occurs.
I think the only way to do this is to use MethodChannel to write and execute native code for each OS from Flutter.
I would like to know if there is a way to execute the scheduled process at the specified time even if the app is in kill or background state in Flutter, even if it uses MethodChannel.
Sorry Its so long. Please let me know.
Thank you very much