투케이2K

129. (TWOK/ERROR) [Android] [FCM] 푸시 Targeting S+ version 31 and above requires .. FLAG_IMMUTABLE 이슈 본문

투케이2K 에러관리

129. (TWOK/ERROR) [Android] [FCM] 푸시 Targeting S+ version 31 and above requires .. FLAG_IMMUTABLE 이슈

투케이2K 2022. 11. 29. 09:20
반응형

[환경 설정 및 설명]

프로그램 : AndroidStudio

설 명 : [FCM] 푸시 java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

 

[에러 원인]

1. [Android 12] build.gradle 빌드 그래들 파일에서 compileSdkVersion , targetSdkVersion 를 31 로 상향 후 PendingIntent 적용 시 FLAG_IMMUTABLE or FLAG_MUTABLE 적용 필요 이슈

W/System.err: java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
W/System.err: 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.
W/System.err:     at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
W/System.err:     at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
W/System.err:     at android.app.PendingIntent.getActivity(PendingIntent.java:451)
W/System.err:     at android.app.PendingIntent.getActivity(PendingIntent.java:415)
 

[해결 방법]

1. PendingIntent 적용 부분에서 build version 빌드 버전 체크해 타겟 31 이상 및 타겟 31 미만 분기 처리 실시

// TODO [안드로이드 타겟 31 이상 분기 처리]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ // [타겟 31 이상]
	pendingIntent = PendingIntent.getActivity(getApplication(), 1, intent,PendingIntent.FLAG_IMMUTABLE);
}
else { // [타겟 31 미만]
	pendingIntent = PendingIntent.getActivity(getApplication(), 1, intent,PendingIntent.FLAG_CANCEL_CURRENT);
}
 

 
반응형
Comments