在gradle文件中将compileSdkVersion从30更新到〉31后,Android手机在应用最小化或关闭时停止接收通知。
Gradle文件:
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'
清单文件:
<service android:name=".service.ABCMessaging" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
错误信息:
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)
有人能提供一些建议吗?
2条答案
按热度按时间r8uurelv1#
尝试在gradle中添加此依赖关系:
此外,如TomInCode所述,将Firebase依赖项更新为最新版本。
carvr3hs2#
您需要在PendingIntent中设置FLAG_IMMUTABLE或FLAG_MUTABLE,如下所示