After updating compileSdkVersion from 30->31 in gradle file, android phones have stopped receiving notifications when the app is minimized or closed.
Gradle File:
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.4.0'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.android.gms:play-services-location:18.0.0'
Manifest File:
<service android:name=".service.ABCMessaging" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Error message:
E/AndroidRuntime: FATAL EXCEPTION: Firebase-AbcMessaging
Process: <>, PID: 29537
java.lang.IllegalArgumentException: <>: 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.
at android.app.PendingIntent.checkFlags(PendingIntent.java:377)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:460)
at android.app.PendingIntent.getActivity(PendingIntent.java:446)
at android.app.PendingIntent.getActivity(PendingIntent.java:410)
at com.google.firebase.messaging.zzb.zza(com.google.firebase:firebase-messaging@@20.1.0:59)
at com.google.firebase.messaging.zzd.zza(com.google.firebase:firebase-messaging@@20.1.0:33)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.1.0:69)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.1.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.0.0:2)
at java.lang.Thread.run(Thread.java:1012)
Can someone please provide any pointers?
2
Answers
You need to set FLAG_IMMUTABLE or FLAG_MUTABLE in your PendingIntent like below
Try adding this dependency in the gradle:
Also, as TomInCode mentioned, update the Firebase dependencies to the latest version.