I'm using Flutter local notification plugin for alarm app, the alarm fire when the app is opened or closed but when it's in the background it's not working until it resumed even it's not at the correct time, I know it's a strange thing but it's happening
Initialization:
Future<void> initNotifications() async {
final initSettingsAndroid =
const AndroidInitializationSettings("@mipmap/ic_launcher");
final initSettings = InitializationSettings(
android: initSettingsAndroid,
);
await FlutterLocalNotificationsPlugin().initialize(initSettings);
tz.initializeTimeZones();
final String currentTimeZone =
await FlutterNativeTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(currentTimeZone));
}
alarm function:
void alarm(String title, String body, DateTime fireTime) async {
const androidPlatformChannalSpecifics = AndroidNotificationDetails(
"alarm notification",
"alarm notification",
"Channal for Alarm Notification",
icon: "@mipmap/ic_launcher",
sound: RawResourceAndroidNotificationSound("alarm"),
importance: Importance.max,
priority: Priority.max,
fullScreenIntent: true,
);
const notificationDetails =
NotificationDetails(android: androidPlatformChannalSpecifics);
await FlutterLocalNotificationsPlugin().zonedSchedule(
0,
title,
body,
TZDateTime.from(fireTime, tz.local),
notificationDetails,
payload: "isPressed",
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
}
My permissions and receivers:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application
android:label="Prodkit"
android:icon="@mipmap/ic_launcher">
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:showWhenLocked="true"
android:turnScreenOn="true">
I don't know what's the problem exactly but I tried a lot of things and it's not working.