Problem with Scheduling Alarms Using alarm Package in Background Tasks with work_manager #584
Open
4 tasks done
Labels
bug
Something isn't working
Version
Describe the error
I am facing an issue while trying to schedule alarms using the alarm package within a work_manager background task. The task to schedule alarms works correctly when executed in the foreground, but when executed in the background, it fails to schedule alarms. The issue seems to occur at the line:
Dart code:
final result = await Alarm.set(alarmSettings: alarmSettings);
Steps to Reproduce:
Use the work_manager package to execute a background task.
Inside the background task, try scheduling an alarm using the alarm package with the following settings:
Dart code:
final alarmSettings = AlarmSettings(
id: 67,
dateTime: DateTime.now().add(Duration(seconds: 10)),
assetAudioPath: 'assets/audio/azan.mp3',
loopAudio: true,
vibrate: true,
fadeDuration: 3.0,
warningNotificationOnKill: Platform.isIOS,
androidFullScreenIntent: true,
notificationSettings: const NotificationSettings(
title: 'Prayer Notification',
body: 'Time for prayer!',
stopButton: 'Stop Alarm',
icon: 'notification_icon',
),
);
final result = await Alarm.set(alarmSettings: alarmSettings);
The alarm fails to schedule when the task is executed in the background.
Expected Behavior:
The alarm should be scheduled correctly even when the task is running in the background.
Actual Behavior:
The Alarm.set() method does not successfully schedule the alarm when executed in the background. The program execution is blocked, and no error or output is produced in the console.
Environment:
Platform: Android / iOS (specify which platform you are using)
Flutter Version: latest
alarm Package Version: 4.1.1
work_manager Package Version: [Your work_manager version]
OS Version: [Android version / iOS version]
Additional Information:
I've tried using try-catch blocks around the Alarm.set() method, but it doesn't seem to catch any errors.
The issue occurs specifically when trying to run background tasks with work_manager.
I have also verified that the necessary permissions are granted for background tasks and notifications.
The alarm works as expected in the foreground but not in the background.
Possible Cause:
It appears that the alarm package does not properly handle alarm scheduling when executed in a background task on certain platforms, particularly Android and iOS.
Request:
Could you investigate and provide any guidance or solutions on how to reliably schedule alarms using the alarm package in background tasks with the work_manager package?
The text was updated successfully, but these errors were encountered: