FirebaseMessagingService

public class FirebaseMessagingService extends Service

Base class for receiving messages from Firebase Cloud Messaging.

Extending this class is required to be able to handle downstream messages. It also provides functionality to automatically display notifications, and has methods that are invoked to give the status of upstream messages.

Override base class methods to handle any events required by the application. Methods are invoked on a background thread.

Include the following in the manifest:

 <service android:name=".YourFirebaseMessagingService">
     <intent-filter>
         <action android:name="com.google.firebase.MESSAGING_EVENT" />
     </intent-filter>
 </service>

Inherited Constant Summary

Public Constructor Summary

Public Method Summary

void
onDeletedMessages()
Called when the FCM server deletes pending messages.
void
onMessageReceived(RemoteMessage message)
Called when a message is received.
void
onMessageSent(String msgId)
Called when an upstream message has been successfully sent to the GCM connection server.
void
onSendError(String msgId, Exception exception)
Called when there was an error sending an upstream message.

Inherited Method Summary

Public Constructors

public FirebaseMessagingService ()

Public Methods

public void onDeletedMessages ()

Called when the FCM server deletes pending messages. This may be due to:

  1. Too many messages stored on the FCM server. This can occur when an app's servers send a bunch of non-collapsible messages to FCM servers while the device is offline.
  2. The device hasn't connected in a long time and the app server has recently (within the last 4 weeks) sent a message to the app on that device.

It is recommended that the app do a full sync with the app server after receiving this call. See here for more information.

public void onMessageReceived (RemoteMessage message)

Called when a message is received.

This is also called when a notification message is received while the app is in the foreground. The notification parameters can be retrieved with getNotification().

Parameters
message Remote message that has been received.

public void onMessageSent (String msgId)

Called when an upstream message has been successfully sent to the GCM connection server.

Parameters
msgId of the upstream message sent using send(RemoteMessage).

public void onSendError (String msgId, Exception exception)

Called when there was an error sending an upstream message.

Parameters
msgId of the upstream message sent using send(RemoteMessage).
exception description of the error, typically a SendException.