2017-09-16 1 views
0

FCM 서비스. NotificationDatabaseHandler는 헬퍼 클래스입니다. 메시지 제목 및 현재 시간 저장.앱이 포 그라운드에있을 때 앱이 백그라운드에서 작동하는 동안 FCM 메시지를 저장하지 못했습니다.

public class ApplicationFCMService extends FirebaseMessagingService { 

    private static final String TAG = ApplicationFCMService.class.getName(); 
    private NotificationUtils notificationUtils; 
    private NotificationDatabaseHandler databaseHandler; 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     super.onMessageReceived(remoteMessage); 

     Log.e(TAG, "From: " + remoteMessage.getFrom()); 
     databaseHandler = new NotificationDatabaseHandler(getApplicationContext()); 

     if (remoteMessage.getNotification() != null) { 
      Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody()); 
      handleNotification(remoteMessage.getFrom(), remoteMessage.getNotification().getBody()); 

      databaseHandler.addNotification(remoteMessage.getNotification().getBody(), getDate()); 
      // Log.d("FCM", messagesSet.toString()); 
      Log.d("FCM", remoteMessage.getNotification().getBody()); 
     } 

     // Check if message contains a data payload. 
     if (remoteMessage.getData().size() > 0) { 
      Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString()); 

      try { 
       JSONObject json = new JSONObject(remoteMessage.getData().toString()); 
       handleDataMessage(json); 
      } catch (Exception e) { 
       Log.e(TAG, "Exception: " + e.getMessage()); 
      } 
     } 
    } 
+0

검사 : https://stackoverflow.com/questions/45875859/fcm-onmessagereceived-not-calling-android/45880920#45880920 – Maddy

+0

https://stackoverflow.com/questions/45267335/create-an-repetitive -high-pitch-alarm-on-a-remote-trigger-app-not-run-run/45406863 # 45406863 –

+0

Firebase에서 "Data"로 알림을 보낼 방법이 있습니까? –

답변

0

나는 데이터 통지 (테스트 용)를 보내기 위해 우편 배달부를 사용했습니다. 데이터 메시지 수신시 onMessageReceived() 메소드가 실행됩니다. 이제 앱이 백그라운드에 있어도 데이터베이스에 알림을 저장할 수 있습니다. 이 ans와

관련 문제