简体   繁体   中英

After upgrading android to 31 app crashes when receiving push notifications android 12 or above devices

I have a push notifications issue after upgrading android to 31, app crashes when receiving push notifications on android 12 or above devices

onesignal_flutter: ^2.6.4

buildscript { repositories { maven { url 'https://plugins.gradle.org/m2/'} } dependencies { classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.4, 0.99.99]' } }

implementation 'com.onesignal:OneSignal:3.13.1'

E/AndroidRuntime(22706):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:4480)
E/AndroidRuntime(22706):    at android.app.ActivityThread.access$1800(ActivityThread.java:277)
E/AndroidRuntime(22706):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
E/AndroidRuntime(22706):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(22706):    at android.os.Looper.loopOnce(Looper.java:211)
E/AndroidRuntime(22706):    at android.os.Looper.loop(Looper.java:300)
E/AndroidRuntime(22706):    at android.app.ActivityThread.main(ActivityThread.java:8282)
E/AndroidRuntime(22706):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(22706):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
E/AndroidRuntime(22706):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1074)
E/AndroidRuntime(22706): Caused by: java.lang.IllegalArgumentException: com.myapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(22706): 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(22706):    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime(22706):    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
E/AndroidRuntime(22706):    at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
E/AndroidRuntime(22706):    at com.onesignal.GenerateNotification.getNewActionPendingIntent(GenerateNotification.java:189)
E/AndroidRuntime(22706):    at com.onesignal.GenerateNotification.createGenericPendingIntentsForNotif(GenerateNotification.java:398)
E/AndroidRuntime(22706):    at com.onesignal.GenerateNotification.showNotification(GenerateNotification.java:382)
E/AndroidRuntime(22706):    at com.onesignal.GenerateNotification.fromJsonPayload(GenerateNotification.java:110)
E/AndroidRuntime(22706):    at com.onesignal.NotificationBundleProcessor.ProcessJobForDisplay(NotificationBundleProcessor.java:107)
E/AndroidRuntime(22706):    at com.onesignal.NotificationBundleProcessor.ProcessFromGCMIntentService(NotificationBundleProcessor.java:90)
E/AndroidRuntime(22706):    at com.onesignal.GcmBroadcastReceiver.startGCMService(GcmBroadcastReceiver.java:138)
E/AndroidRuntime(22706):    at com.onesignal.GcmBroadcastReceiver.processOrderBroadcast(GcmBroadcastReceiver.java:129)
E/AndroidRuntime(22706):    at com.onesignal.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:70)
E/AndroidRuntime(22706):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:4467)


Update the library to the last version release notes OneSignal: and flutter , because there are new requirements starting Android 12 as you can see in the message:

E/AndroidRuntime(22706): Caused by: java.lang.IllegalArgumentException: com.myapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(22706): 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM