Handling Messages - Android

If you are here, it’s because you want custom notifications. Find out here how to handle those.
  1. Handling custom messages
  2. Override onMessageReceived



Handling custom messages

Adding rich content like location or a map in a notification is considered as managing custom messages.

To receive custom messages, use a service that extends FirebaseMessagingService. Your service should override the onMessageReceived and onDeletedMessages callbacks.

Messages should be handled within 20 seconds of receipt (10 seconds on Android Marshmallow). Note that the time window may be shorter depending on OS delays incurred ahead of calling onMessageReceived.

If delays is exceeded, various OS behaviors such as Android O’s background execution limits may interfere with your ability to complete your work. For more information see the overview on message priority (here https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message).

onMessageReceived is provided for most message types, with the following exceptions:

Override onMessageReceived

By overriding the method FirebaseMessagingService.onMessageReceived, you can perform actions based on the received RemoteMessage object and get the message data:

public class WoosmapMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        WoosmapMessageBuilderMaps messageBuilder = new WoosmapMessageBuilderMaps(this, MainActivity.class);
        WoosmapMessageDatas messageDatas = new WoosmapMessageDatas(remoteMessage.getData());
        if (messageDatas.isLocationRequest () && messageDatas.timestamp != null) {
            messageBuilder.sendWoosmapNotification(messageDatas);
        }

    }
}