flutter - 如何在 Flutter 上运行多个通知,每个通知都有指定的时间?
问题描述
我使用每小时重复一次的通知,具有不同的 id 和 channel ,但我只得到了第一个 evert time 和其他被阻止的,有时只有 lastone。
这是我的通知功能
Future<void> _scheduleNotification(id,duration,channelname,channelid,soundandroid,soundios,message,title) async {
var vibrationPattern = Int64List(4);
vibrationPattern[0] = 0;
vibrationPattern[1] = 1000;
vibrationPattern[2] = 5000;
vibrationPattern[3] = 2000;
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
channelid,
channelname,
'your other channel description',
icon: '@mipmap/ic_launcher',
importance: Importance.Max,
priority: Priority.High,
ongoing: true,
autoCancel: false,
sound: RawResourceAndroidNotificationSound(soundandroid),
largeIcon: DrawableResourceAndroidBitmap('@mipmap/ic_launcher'),
vibrationPattern: vibrationPattern,
enableLights: true,
color: const Color.fromARGB(255, 255, 0, 0),
ledColor: const Color.fromARGB(255, 255, 0, 0),
ledOnMs: 1000,
ledOffMs: 500);
var iOSPlatformChannelSpecifics =
IOSNotificationDetails(sound:soundios);
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.periodicallyShow(
id,
title,
message,
RepeatInterval.Hourly,
platformChannelSpecifics,
);
}
我调用这个函数来执行
Future<void> smartnotificationcall(channelname,id)
async{
if(channelname=="clean"){ Duration(seconds:5); return _scheduleNotification(1,20,'clean',"clean","clean","clean.wav",'test','test');}
if(channelname=="sport"){ Duration(seconds:20); return _scheduleNotification(2,30,"sport","sport","sport","sport.wav",'test','test');}
if(channelname=="eat"){ Duration(seconds:40); return _scheduleNotification(3,30,"eat","eat","eat","eat.wav",'test','test');}
if(channelname=="getout"){ Duration(seconds:50); return _scheduleNotification(4,30,"getout","getout","getout","getout.wav",'test','test');
}
}
解决方案
您使用哪个平台?Android 使用AlarmManager来安排重复通知,它们是不准确的,这是记录在案的 Android 行为。
推荐阅读
- recursion - 使用函数保护理解 Erlang 基本递归
- html - 为什么当我为元素硬编码字体大小时,它会在浏览器中响应地调整大小,为什么在 Angular 中不会发生这种情况?
- xml - 如果查询项目的多个属性,如何制作 XSLT
- mongodb - Express 出现错误,无法发送请求
- javascript - 将 PDF 与 PDF-LIB 合并
- java - 如何用icu音译成中文?
- r - 在 for 循环 R 中保持更改
- r - 使用 updateR 更新 R 时出错:参数长度为零
- python-3.x - Python的最小距离点束
- java - 在 Java 中干净地包装一个数据包对象并传递给具有不同参数的方法