언젠가 부터 안드로이드 O 오레오 버전 이후 휴대폰에서 푸시가 안오기 시작한다.

 

테스트

- FCM 콘솔에서 메시지 전송 (수신 OK)

- push https://fcm.googleapis.com/fcm/send로 POST 전송(수신X)

 

원인 : GCM 에서 FCM 으로 바뀌면서 json 형식에 Notification 영역이 생김

 

약 1개월전 앱이 포그라운드일때 푸시 안오는 현상으로 코드 수정후 업데이트함.

 

그때 수정한 코드가 문제....

 

다시 처음부터 시작..

 

기존 GCM 관련 코드 전부 걷어내고 FCM 으로 코드작성

 

.json파일 연동 부터 시작.

 

(포그라운드) 안드로이드에서 푸시 메시지를 받으면 FirebaseMessagingService.java 의 OnMessageReceived를 타게됨

 

(백그라운드) Logcat 에서 로그가 안찍힘(그런데 푸시알림은 옴..)

 

구글링 해서 찾은 결과.

 

백그라운드에서는 FCM 으로 전송할때  json 에서 Notification 의 title 과 body가 있으면 안드로이드에서 직접 처리해서 푸시알림을 띄우는것 같음

 

안드로이드 Oreo이상에서는 아래 코드 필수

 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {


            NotificationChannel notificationChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT);

            // Configure the notification channel.
            notificationChannel.setDescription(description);

            notificationChannel.enableLights(true);
            // Sets the notification light color for notifications posted to this
            // channel, if the device supports this feature.
            notificationChannel.setLightColor(Color.RED);

            notificationChannel.enableVibration(true);
            notificationChannel.setVibrationPattern(vibraPattern);

            notificationManager.createNotificationChannel(notificationChannel);
        }

Oreo이상 버전을 체크한후 채널을 생성해 주어야함.

 

채널을 생성해주지 않으면 앱에서는 푸시알림을 받지않음 (맨처음에 나타났던 문제... Oreo이상버전에서 푸시알림이 오지않는 문제)

 

 

코드 수정후 문제점.

 

- Developer warning for package "패키지명" Failed to post notificcation on channel "null" See log for more detail

 

에러 발생 

 

채널을 생성해주어야 없어지는 에러라는데 채널을 생성해 주었는데도 계속 나타난다.

 

무엇때문에 나타나는 에러인지는 확인이 필요하다.

 

 

 

 

 

 

 

 

 

 

 

반응형

+ Recent posts