Repository: MaikuB/flutter_local_notifications

Issue #1476: FLAG_MUTABLE on PendingIntent error for Android 12 / API 31?
Created: 2022-02-10T15:04:07Z
Experienced on version 10.0.0-dev.5 with Android Targeting/Compiling to SDK Version 32 with emulated Pixel 2 device running API 31 / Android 12.
Describe the bug
Notification with actions is zoned scheduled when app is inactive; notification tries to fire at scheduled time and the following error occurs:
E/AndroidRuntime(29062): java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.IllegalArgumentException: com.example.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(29062): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/AndroidRuntime(29062): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4317)
E/AndroidRuntime(29062): 	at android.app.ActivityThread.access$1600(ActivityThread.java:247)
E/AndroidRuntime(29062): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064)
E/AndroidRuntime(29062): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(29062): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(29062): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(29062): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime(29062): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(29062): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(29062): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(29062): Caused by: java.lang.IllegalArgumentException: com.example.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(29062): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/AndroidRuntime(29062): 	at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime(29062): 	at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
E/AndroidRuntime(29062): 	at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
E/AndroidRuntime(29062): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:241)
E/AndroidRuntime(29062): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1074)
E/AndroidRuntime(29062): 	at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java:41)
E/AndroidRuntime(29062): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4308)
E/AndroidRuntime(29062): 	... 9 more

To Reproduce

Use an emulated device running Android 12 / API 31.
Run app and setup a notification to fire as a zonedSchedule().
Call it.
Wait for scheduled time.

Expected behavior
Notification appears.
Note that everything works fine on other API's less than 31.

Duplicate issue #1814: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Created: 2022-11-27T09:31:01Z

Closing comment (2022-12-05T04:04:18Z): You'll need to provide a link to a minimal app that can reproduce the issue and only uses this plugin. As implied by @FlaviusBanc, this should've been to do with the version of the plugin used and this issue was reported in #1476 and resolved in version 10 before

I am using version 4.0.1, do you have a fix? thank