awesome_notifications icon indicating copy to clipboard operation
awesome_notifications copied to clipboard

Android 12 SDK 31 - Awesome Notifications cannot schedule notifications - S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

Open Zelfapp opened this issue 2 years ago • 12 comments

On Android 12 targeting SDK 31 I am getting this error and cannot schedule notifications using Awesome Notifications.

Using awesome_notifications: ^0.6.17

W/System.err(14791): java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
W/System.err(14791): 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.
W/System.err(14791): 	at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
W/System.err(14791): 	at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
W/System.err(14791): 	at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
W/System.err(14791): 	at me.carda.awesome_notifications.notifications.NotificationScheduler.scheduleNotification(NotificationScheduler.java:232)
W/System.err(14791): 	at me.carda.awesome_notifications.notifications.NotificationScheduler.doInBackground(NotificationScheduler.java:127)
W/System.err(14791): 	at me.carda.awesome_notifications.notifications.NotificationScheduler.doInBackground(NotificationScheduler.java:31)
W/System.err(14791): 	at android.os.AsyncTask$3.call(AsyncTask.java:394)
W/System.err(14791): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err(14791): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
W/System.err(14791): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(14791): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(14791): 	at java.lang.Thread.run(Thread.java:920)

I see some recent chatter out there on this issue.

https://stackoverflow.com/questions/69783824/targeting-s-version-31-and-above-requires-that-one-of-flag-immutable-or-flag https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE

Zelfapp avatar Nov 09 '21 21:11 Zelfapp

That change was applied here and will be available officially at 0.6.18

rafaelsetragni avatar Nov 14 '21 13:11 rafaelsetragni

Version 0.6.18+1 released! Please take a look and check for me if your issue is solved.

rafaelsetragni avatar Nov 24 '21 00:11 rafaelsetragni

Version 0.6.18+1 released! Please take a look and check for me if your issue is solved.

Using version 0.6.18+2 and the issue continues:

I/flutter (11199): SystemChannels> AppLifecycleState.paused
W/System.err(11199): java.lang.IllegalArgumentException: ca.adambridges.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
W/System.err(11199): 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.
W/System.err(11199): 	at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
W/System.err(11199): 	at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
W/System.err(11199): 	at android.app.PendingIntent.getActivity(PendingIntent.java:444)
W/System.err(11199): 	at android.app.PendingIntent.getActivity(PendingIntent.java:408)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationBuilder.createActionButtons(NotificationBuilder.java:683)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationBuilder.getNotificationBuilderFromModel(NotificationBuilder.java:430)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationBuilder.createNotification(NotificationBuilder.java:118)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationBuilder.createNotification(NotificationBuilder.java:74)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationSender.showNotification(NotificationSender.java:209)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationSender.doInBackground(NotificationSender.java:129)
W/System.err(11199): 	at me.carda.awesome_notifications.notifications.NotificationSender.doInBackground(NotificationSender.java:33)
W/System.err(11199): 	at android.os.AsyncTask$3.call(AsyncTask.java:394)
W/System.err(11199): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err(11199): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
W/System.err(11199): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(11199): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(11199): 	at java.lang.Thread.run(Thread.java:920)
D/NotificationScheduler(11199): Scheduled created
D/AwesomeNotificationsPlugin(11199): Notification created
I/flutter (11199): notification created.

Workmanager was also experiencing this issue but I solved it by implementing this within the app level build.gradle: implementation 'androidx.work:work-runtime:2.7.1'

A similar implementation may be required for Awesome Notifications?

AdamBridges avatar Nov 30 '21 18:11 AdamBridges

https://github.com/rafaelsetragni/awesome_notifications/blob/facacfa1a03f090fbf1a81e4b07d3034616e696d/android/src/main/java/me/carda/awesome_notifications/notifications/NotificationBuilder.java#L678

All flags was already updated. Try to clean your project and try again.

rafaelsetragni avatar Nov 30 '21 19:11 rafaelsetragni

https://github.com/rafaelsetragni/awesome_notifications/blob/facacfa1a03f090fbf1a81e4b07d3034616e696d/android/src/main/java/me/carda/awesome_notifications/notifications/NotificationBuilder.java#L678

All flags was already updated. Try to clean your project and try again.

Cleaned and still failing. I think it's because it should be PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT for bitwise operations in Kotlin, no?

https://stackoverflow.com/questions/23634970/what-is-kotlin-equivalent-for-bitwise-or-with-assignment https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/or.html

AdamBridges avatar Nov 30 '21 20:11 AdamBridges

But flags are bit values and the single bar is an OR operation in bit level. This was already done in the file linked above.

You can try to edit your local file and put FLAG_MUTABLE instead.

Tou can also try to update your kotlin version inside build.gradle

rafaelsetragni avatar Nov 30 '21 20:11 rafaelsetragni

Now i got wats going on. The pendingIntent for disabled action is still 0.

You can put with no problem the immutable flag there. It will fix the problem.

On future release it will be already fixed, because ive changed everything to adapt to SDK 21.

Thank for your advise and this will be fixed on next release.

rafaelsetragni avatar Nov 30 '21 20:11 rafaelsetragni

Yep! That fixed it for me. And I'm glad I could help! :)

AdamBridges avatar Nov 30 '21 20:11 AdamBridges

Still happening a similar issue with version ^0.6.19:

E/GeneratedPluginRegistrant(13717): Error registering plugin awesome_notifications, me.carda.awesome_notifications.AwesomeNotificationsPlugin
E/GeneratedPluginRegistrant(13717): java.lang.IllegalArgumentException: com.landa.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/GeneratedPluginRegistrant(13717): 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/GeneratedPluginRegistrant(13717): 	at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/GeneratedPluginRegistrant(13717): 	at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
E/GeneratedPluginRegistrant(13717): 	at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
E/GeneratedPluginRegistrant(13717): 	at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:557)
E/GeneratedPluginRegistrant(13717): 	at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:528)
E/GeneratedPluginRegistrant(13717): 	at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:492)
E/GeneratedPluginRegistrant(13717): 	at android.support.v4.media.session.MediaSessionCompat.<init>(MediaSessionCompat.java:466)
E/GeneratedPluginRegistrant(13717): 	at me.carda.awesome_notifications.AwesomeNotificationsPlugin.AttachAwesomeNotificationsPlugin(AwesomeNotificationsPlugin.java:160)
E/GeneratedPluginRegistrant(13717): 	at me.carda.awesome_notifications.AwesomeNotificationsPlugin.onAttachedToEngine(AwesomeNotificationsPlugin.java:132)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.add(FlutterEngineConnectionRegistry.java:145)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:41)
E/GeneratedPluginRegistrant(13717): 	at java.lang.reflect.Method.invoke(Native Method)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:354)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:262)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:242)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:162)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.lambda$startBackgroundIsolate$0$FlutterFirebaseMessagingBackgroundExecutor(FlutterFirebaseMessagingBackgroundExecutor.java:167)
E/GeneratedPluginRegistrant(13717): 	at io.flutter.plugins.firebase.messaging.-$$Lambda$FlutterFirebaseMessagingBackgroundExecutor$zxJ5LgPXbKxXUnPaKdrwAxLuPJc.run(Unknown Source:8)
E/GeneratedPluginRegistrant(13717): 	at android.os.Handler.handleCallback(Handler.java:938)
E/GeneratedPluginRegistrant(13717): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/GeneratedPluginRegistrant(13717): 	at android.os.Looper.loopOnce(Looper.java:201)
E/GeneratedPluginRegistrant(13717): 	at android.os.Looper.loop(Looper.java:288)
E/GeneratedPluginRegistrant(13717): 	at android.app.ActivityThread.main(ActivityThread.java:7798)
E/GeneratedPluginRegistrant(13717): 	at java.lang.reflect.Method.invoke(Native Method)
E/GeneratedPluginRegistrant(13717): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/GeneratedPluginRegistrant(13717): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

🤔

efraespada avatar Dec 21 '21 11:12 efraespada

Now i got! Is the media session compat library outdated. I gonna upgrade it to the next version. Thank you!

rafaelsetragni avatar Dec 21 '21 17:12 rafaelsetragni

Any updates? I am facing this issue too

SlavisDEV avatar Apr 07 '22 09:04 SlavisDEV

I fixed this by changing every occurrence of PendingIntent.FLAG_UPDATE_CURRENT inside NotificationBuilder.java and NotificationScheduler.java to PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT

SlavisDEV avatar Apr 07 '22 09:04 SlavisDEV

Hi! Sorry for taking so long to respond to your issue on GitHub. I was focused on releasing the new 0.7.0 version of awesome_notifications and awesome_notifications_fcm and i didn't had time enough to do both. But now I can answer all your questions.

So now i'm asking you to recreate this topic using the new issue template. There's a lot of missing informations that i need to understand your problem, and all the instructions are already in the new issue template. Also, remember to check beforehand if your issue was posted by another user.

So I will automatically close all previous issues so far. Sorry for the inconvenience and i will be waiting for your new issue request.

Thank you so much for your support!

rafaelsetragni avatar Sep 29 '22 18:09 rafaelsetragni