在后台发出颤动的声音警报,并在单击通知时取消。
我正在尝试创建一个用于测试/学习颤振的基本警报应用程序。我的应用程序的高级设计如下所示:
创建警报:
(A)。用户创建警报
(b)。我使用 android_alarm_manager 来安排闹钟
(c)。在闹钟回调中,我使用 FlutterRingtonePlayer.playAlarm()
(d)。用于flutter_local_notification在闹钟响起时显示通知,以便用户可以取消闹钟。
当用户点击通知时:
我收到 的回调flutter_local_notification,它打开了应用程序。
我FlutterRingtonePlayer.stop()这样做了,但这并不能阻止警报。
它现在不起作用,因为FlutterRingtonePlayer当应用程序从通知再次启动时会再次构建。
我能想到的可能的解决方案是:
FlutterRingtonePlayer在手机的共享内存中,以便我可以在取消闹钟时重复使用它。也许以某种方式序列化它?还有更多吗?有更好的方法来做到这一点吗?
Here is my code:
--------------- Scheduling alarm -----------------------------------
void scheduleAlarm(Alarm alarm) {
alarm.alarmTime =
getUpdatedAlarmDateTime(TimeOfDay.fromDateTime(alarm.alarmTime));
AndroidAlarmManager.oneShot(
alarm.alarmTime.difference(DateTime.now()), alarm.alarmId, soundAlarm,
wakeup: true, alarmClock: true, rescheduleOnReboot: true);
}
void soundAlarm(int alarmId) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
var …Run Code Online (Sandbox Code Playgroud)