As per Google's policy, I updated my targetSdkVersion and compileSdkVersion to 31. But I noticed that the Flutter local notification package now throws error for incoming messages as below:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 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.
I went through all the Stack overflow answers related to this error and made following changes:
- Added below Java and Kotlin dependencies in build.gradle file:build.gradle file
- Added this receiver below activity tag: Receiver tag
- Added exported flag under activity tag: Exported flag
- Updated gradle version to latest in gradle-wrapper.properties: Latest gradle version I am not using any PendingIntent in my code, and simulating app on simulator with API 31 level. Could someone please help me in resolving this issue with message notifications?
Looks like there's an issue in the
flutter_local_notifications
repo that provides the solution. See the issue hereIf you don't want to update the version of the package you can fork the version you're using and fix the issues locally.
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationDetails.id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
and replace withPendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationDetails.id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
You have to do this for every instance of
PendingIntent
. It worked for me.