Ejemplo n.º 1
0
 @Override
 public void onMessageReceived(RemoteMessage remoteMessage) {
   Log.i(
       TAG,
       "Message received: "
           + remoteMessage.getMessageType()
           + ", "
           + remoteMessage.getData().toString());
 }
Ejemplo n.º 2
0
  @Override
  public void onMessageReceived(RemoteMessage message) {
    String from = message.getFrom();

    Bundle data = new Bundle();
    for (Map.Entry<String, String> entry : message.getData().entrySet()) {
      data.putString(entry.getKey(), entry.getValue());
    }

    RxFcm.Notifications.init(getApplication());
    RxFcm.Notifications.onNotificationReceived(from, data);
  }
  // [START receive_message]
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are
    // handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages
    // are the type
    // traditionally used with GCM. Notification messages are only received here in
    // onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated
    // notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both
    // notification
    // and data payloads are treated as notification messages. The Firebase console always sends
    // notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
      Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
      Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
      sendNotification(remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
  }