英文:
There is a way to send a notification every 4 hours with local notifications?
问题
我想知道是否有办法使用`flutter_local_notifications`每隔4小时发送一次通知。
这个包有一个重复通知的功能,但你只能在以下4个选项中选择:
`RepeatInterval.everyMinute`
`RepeatInterval.hourly`
`RepeatInterval.daily`
`RepeatInterval.weekly`
代码片段:
```Dart
未来<void> _repeatNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'repeating channel id', 'repeating channel name',
channelDescription: 'repeating description');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.periodicallyShow(
id++,
'repeating title',
'repeating body',
RepeatInterval.hourly, // <-- 在这里
notificationDetails,
androidAllowWhileIdle: true,
);
}
有人知道是否有办法以特定的小时数重复,而不是一般的“每小时”吗?谢谢
<details>
<summary>英文:</summary>
I'm wondering if there is a way to send a notification every 4 hours with `flutter_local_notifications`.
This package have a repeat notification utility but you have to choose between a repeat interval, but it only provides 4 choices:
`RepeatInterval.everyMinute`
`RepeatInterval.hourly`
`RepeatInterval.daily`
`RepeatInterval.weekly`
A code snippet:
```Dart
Future<void> _repeatNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'repeating channel id', 'repeating channel name',
channelDescription: 'repeating description');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.periodicallyShow(
id++,
'repeating title',
'repeating body',
RepeatInterval.hourly, // <-- HERE
notificationDetails,
androidAllowWhileIdle: true,
);
}
Someone know if there is a way to repeat with a precise amount of hours instead a generic "hourly"? Thanks
答案1
得分: 1
以下是要翻译的内容:
您可以使用以下任一软件包:
这些软件包允许您在应用程序中安排后台任务。
然后,您可以使用 "flutter_local_notifications" 软件包作为任务的一部分触发通知。
英文:
You can use either of these packages:
These packages allow you to schedule background tasks in your app.
Then you can use flutter_local_notifications
package to trigger a notification as part of the task.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论