dart - Flutter local notification throws error when i try to setup scheduled Notification - Stack Overflow

admin2025-04-30  0

Error Message:

Fallback to settings intent failed: PlatformException(error, No Activity found to handle Intent {
act=android.settings.ACTION_MANAGE_OVERLAY_PERMISSION (has extras) }, null,
android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.settings.ACTION_MANAGE_OVERLAY_PERMISSION (has extras) }

Instant notification works well. This has to do with android configuration but i have tried everything i know

 static Future<void> scheduleNotification(Map details) async {
    tz.initializeTimeZones();
    await requestExactAlarmPermission2();
    final dueDate = details['dueDate'];
    DateTime parsedDate;
    // Check if dueDate is a String
    if (dueDate is String) {
      // If dueDate is a string, parse it
      parsedDate = DateTime.parse(dueDate.replaceAll(' ', 'T'));
    } else if (dueDate is DateTime) {
      // If dueDate is already a DateTime object, use it directly
      parsedDate = dueDate;
    } else {
      throw ArgumentError('Invalid dueDate format');
    }
    final scheduledNotificationDateTime = tz.TZDateTime.from(parsedDate, tz.local);
    await flutterLocalNotificationsPlugin.zonedSchedule(
      details['id'],
      'Payment Reminder',
      'It\'s time to pay for your ${details['for']}: ${details['name']}',
      tz.TZDateTime.from(scheduledNotificationDateTime, tz.local),
      NotificationDetails(
        android: AndroidNotificationDetails(
            channel.id,
            channel.name,
            channelDescription: channel.description,
            icon: 'mipmap/notification',
            playSound: true
        ),
      ),
      uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
      matchDateTimeComponents: DateTimeComponents.dateAndTime
    );
  }

the method to trigger the notification

Error Message:

Fallback to settings intent failed: PlatformException(error, No Activity found to handle Intent {
act=android.settings.ACTION_MANAGE_OVERLAY_PERMISSION (has extras) }, null,
android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.settings.ACTION_MANAGE_OVERLAY_PERMISSION (has extras) }

Instant notification works well. This has to do with android configuration but i have tried everything i know

 static Future<void> scheduleNotification(Map details) async {
    tz.initializeTimeZones();
    await requestExactAlarmPermission2();
    final dueDate = details['dueDate'];
    DateTime parsedDate;
    // Check if dueDate is a String
    if (dueDate is String) {
      // If dueDate is a string, parse it
      parsedDate = DateTime.parse(dueDate.replaceAll(' ', 'T'));
    } else if (dueDate is DateTime) {
      // If dueDate is already a DateTime object, use it directly
      parsedDate = dueDate;
    } else {
      throw ArgumentError('Invalid dueDate format');
    }
    final scheduledNotificationDateTime = tz.TZDateTime.from(parsedDate, tz.local);
    await flutterLocalNotificationsPlugin.zonedSchedule(
      details['id'],
      'Payment Reminder',
      'It\'s time to pay for your ${details['for']}: ${details['name']}',
      tz.TZDateTime.from(scheduledNotificationDateTime, tz.local),
      NotificationDetails(
        android: AndroidNotificationDetails(
            channel.id,
            channel.name,
            channelDescription: channel.description,
            icon: 'mipmap/notification',
            playSound: true
        ),
      ),
      uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
      matchDateTimeComponents: DateTimeComponents.dateAndTime
    );
  }

the method to trigger the notification

Share Improve this question asked Jan 5 at 1:01 Tope AladesiunTope Aladesiun 111 bronze badge 1
  • I think you're missing these in androidManifest, <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> – Meshkat Shadik Commented Jan 5 at 14:07
Add a comment  | 

1 Answer 1

Reset to default 0

Notice that this error can show up if you not safeguard the request to the action_manage_overlay_permission. Android developer:

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

Verify you are not missing <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> in the Android manifest.

But the error should propably come from await requestExactAlarmPermission2(); could you give more details on this code?

转载请注明原文地址:http://anycun.com/QandA/1746022699a91472.html