0

Firebase에서 알림을 받았지만 만든 클래스가 작동하지 않습니다 (작업과 관련 없음). 기본적으로 표시되는 것처럼 보입니다.MyFirebaseMessagingService가 작동하지 않지만 알림이 표시됩니다.

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     String title = remoteMessage.getNotification().getTitle(); 
     String message = remoteMessage.getNotification().getBody(); 
     String click_action = remoteMessage.getNotification().getClickAction(); 
     Intent intent = new Intent(click_action); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this) 

       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, notifiBuilder.build()); 

    } 
} 

답변

0

알림과 데이터의 두 가지 유형의 FCM 메시지가 있습니다. 이들은 수신 장치에서 다르게 처리됩니다. 데이터 필드가없는 알림 메시지를 보내는 경우 알림은 클라이언트 SDK에 의해 생성되고 onMessageReceived()은 호출되지 않습니다. 이 explained in more detail in the documentation입니다 :

  • 알림 메시지 : FCM은 자동으로 클라이언트 응용 프로그램을 대신하여 장치를 최종 사용자에게 메시지를 표시합니다. 알림 메시지 에는 미리 정의 된 사용자 표시 키 세트와 선택적 데이터 맞춤 키 - 값 쌍의 페이로드가 있습니다.

  • 데이터 메시지 : 클라이언트 앱은 데이터 메시지 처리를 담당합니다. 데이터 메시지에는 맞춤 키 - 값 쌍만 있습니다.