android 버전이 12이상인 기기에서 백그라운드 알림 이벤트 수신시 아래와 같이 에러가 났다.
Exception java.lang.IllegalArgumentException: com.bizentro.uniportal: 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:382)
at android.app.PendingIntent.getActivityAsUser (PendingIntent.java:465)
at android.app.PendingIntent.getActivity (PendingIntent.java:451)
at android.app.PendingIntent.getActivity (PendingIntent.java:415)
at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent (com.google.firebase:firebase-messaging@@21.0.1:5)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo (com.google.firebase:firebase-messaging@@21.0.1:20)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo (com.google.firebase:firebase-messaging@@21.0.1:6)
at com.google.firebase.messaging.DisplayNotification.handleNotification (com.google.firebase:firebase-messaging@@21.0.1:4)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage (com.google.firebase:firebase-messaging@@21.0.1:8)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk (com.google.firebase:firebase-messaging@@21.0.1:8)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent (com.google.firebase:firebase-messaging@@21.0.1:3)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent (com.google.firebase:firebase-messaging@@21.0.1:3)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run
at java.lang.Thread.run (Thread.java:920)
PendingIntent.getActivity()에 분명 PendingIntent.FLAG_IMMUTABLE 추가했는데..
public class MyFirebaseMessagingService extends FirebaseMessagingService {
...
/**
* 서버로부터 수신받은 메시지를 보여준다.
* @param remoteMessage
*/
private void sendNotification(Context context, RemoteMessage remoteMessage) {
...
PendingIntent contentIntent = PendingIntent.getActivity(this, notiId, mainWeb , PendingIntent.FLAG_IMMUTABLE);
}
}
구글링 후 아래와 같이 해결했음.
build.gradle (Module)의 dependencies { } 부분에서 아래 부분 수정함
dependencies {
...
//최신버전으로 수정 (기존 1.0.0)
implementation 'androidx.appcompat:appcompat:1.5.1'
//최신 버전으로 변경(기존 16, 17버전대)
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-iid:21.1.0'
implementation 'com.google.firebase:firebase-messaging:23.1.1'
//추가
implementation 'androidx.work:work-runtime:2.7.1'
...
}
'android' 카테고리의 다른 글
Android Target API Level 34로 변경 후 빌드 안됨. (3) | 2024.10.31 |
---|---|
[FCM] OAuth 2.0 Playground로 message 보내기 (1) | 2024.10.18 |
[cordova] exitApp 플러그인 추가 안됨 (0) | 2024.07.22 |
android 12(sdk version 31) Task :app:processDebugMainManifest FAILED 에러 (0) | 2023.01.06 |
android HTTPS, SSL 인증서 적용하기 (0) | 2022.02.18 |