2

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • answer here: https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase – Yandre World Apr 26 '23 at 13:13

2 Answers2

1

Try adding this dependency in the gradle:

implementation 'androidx.work:work-runtime:2.7.0-alpha05'

Also, as TomInCode mentioned, update the Firebase dependencies to the latest version.

Yuji Bry
  • 304
  • 8
0

You need to set FLAG_IMMUTABLE or FLAG_MUTABLE in your PendingIntent like below

    PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, FLAG_IMMUTABLE);
TomInCode
  • 506
  • 5
  • 11
  • I don't have any PendingIntent in my project. – user3857963 Feb 03 '23 at 14:50
  • OK. Perhaps you should try updating the dependencies to the latest versions. com.google.firebase:firebase-analytics:21.2.0 and com.google.firebase:firebase-messaging:23.1.1 etc. – TomInCode Feb 03 '23 at 15:26
  • Updating dependencies and android studio seems to be useful. Getting this error now while building: Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message) Can't really tell which line of code is throwing the exception. – user3857963 Feb 06 '23 at 14:51
  • On running stack trace: https://ufile.io/qb1swhmv – user3857963 Feb 06 '23 at 16:14
  • This seems to come from a Gradle script. This post may useful to help you fix this: https://stackoverflow.com/a/46850574/8391649 – TomInCode Feb 07 '23 at 06:28