투케이2K

92. (TWOK/WORK) [업무 이슈] Android Build.VERSION_CODES.S 안드로이드 12 기기 이상 카드 리딩 PendingIntent 등록 에러 발생 본문

투케이2K 업무정리

92. (TWOK/WORK) [업무 이슈] Android Build.VERSION_CODES.S 안드로이드 12 기기 이상 카드 리딩 PendingIntent 등록 에러 발생

투케이2K 2024. 9. 10. 18:57
반응형

[제 목]

[업무 이슈] Android Build.VERSION_CODES.S 안드로이드 12 기기 이상 카드 리딩 PendingIntent 등록 에러 발생

 

[내 용]

 

------------------------------------------------------------------------------
[이슈 사항]
------------------------------------------------------------------------------

1. 안드로이드 12 기기 이상 카드 리딩 PendingIntent FLAG_IMMUTABLE or FLAG_MUTABLE 사용 필요 앱 크래시 발생 이슈

------------------------------------------------------------------------------
[원인 파악 및 증상 재현]
------------------------------------------------------------------------------

1. 이전 이전에 개발 된 프로젝트 build gradle 타겟 버전 향상 및 Android X 리팩토링 수행

2. Android 12 기기 이상 Nfc 카드 리딩 기능 동작 

  >> 원본 코드 : PendingIntent.getActivity(getApplication(), 1, intent,PendingIntent.FLAG_CANCEL_CURRENT);

3. 앱 크래시 발생 현상 확인

------------------------------------------------------------------------------
[조치 내용]
------------------------------------------------------------------------------

1. Nfc 카드 리딩 시 Android Os 분기 처리 및 PendingIntent 등록 수행 코드 변경

// 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);
}

------------------------------------------------------------------------------
[참고 사이트]
------------------------------------------------------------------------------

https://blog.naver.com/kkh0977/222941026548?trackingCode=blog_bloghome_searchlist

https://developer.android.com/develop/connectivity/nfc/advanced-nfc?hl=ko#foreground-dispatch

------------------------------------------------------------------------------

 

반응형
Comments