Android 14下awesome_notifications本地定时通知延迟问题求助
Android 14下awesome_notifications定时通知延迟问题
所有通过awesome_notifications设置的本地定时通知均存在不定时长延迟,短则30秒,长则1分钟,偶尔甚至会出现5-7分钟的延迟。已关闭应用电池优化,该问题在debug/release模式、应用前后台状态下均会出现,期望通知能在指定时间精准触发。
实现情况
使用awesome_notifications实现通知服务,通过日期时间选择器让用户设置截止时间,调用NotificationCalendar.fromDate()调度通知。已确保应用初始化时请求通知权限,dueDate配置正确、权限已授予,且包配置符合文档要求。控制台无错误/异常输出,但通知始终无法按时触发,延迟时长在30秒至1分半浮动。此前相关问题多为通知完全失效,未找到针对延迟问题的解决方案。
提供了最小可复现示例仓库,可克隆后在Android Studio中于Android 14物理设备上运行debug和release模式测试。
环境配置
依赖版本
- awesome_notifications: ^0.10.0
- Flutter版本:
Flutter 3.24.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision dec2ee5c1f (2 weeks ago) • 2024-11-13 11:13:06 -0800 Engine • revision a18df97ca5 Tools • Dart 3.5.4 • DevTools 2.37.3
AndroidManifest.xml配置
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application... <receiver android:name="me.carda.awesome_notifications.core.broadcasters.receivers.ScheduledNotificationReceiver" android:exported="true" /> <receiver android:name="me.carda.awesome_notifications.core.broadcasters.receivers.RefreshSchedulesReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver>
android/app/build.gradle配置
android{ ... compileSdk = 34 ndkVersion = "26.1.10909125" ... defaultConfig{ ... minSdk = 23 targetSdk = 34 versionCode = flutter.versionCode versionName = flutter.versionName ...
notification_service.dart核心代码
// Initialize notifications static Future<void> initNotifications() async { _notif.initialize( null, [ NotificationChannel( channelKey: 'task_notif', channelName: 'task_notifications', channelDescription: 'Channel used to notify users about their tasks', importance: NotificationImportance.Max, playSound: true, defaultRingtoneType: DefaultRingtoneType.Notification, enableLights: true, channelShowBadge: true, criticalAlerts: true, ), ], ); // Function used to show notification await _notif.createNotification( content: NotificationContent( id: task.id!, channelKey: 'task_notif', title: 'Task Due Now', body: task.title, actionType: ActionType.Default, payload: { 'task': taskPayload, }, notificationLayout: NotificationLayout.Default, category: NotificationCategory.Reminder, wakeUpScreen: true, ), schedule: NotificationCalendar.fromDate( date: task.dueDate!, allowWhileIdle: true, preciseAlarm: true, ), ); }
内容的提问来源于stack exchange,提问作者Husen Patel
相关产品推荐
相关产品推荐

