Skip to content

Instantly share code, notes, and snippets.

@pandeia
Created January 27, 2018 08:00
Show Gist options
  • Select an option

  • Save pandeia/2a8d6de927b0f4c3201ae9a9accf82d5 to your computer and use it in GitHub Desktop.

Select an option

Save pandeia/2a8d6de927b0f4c3201ae9a9accf82d5 to your computer and use it in GitHub Desktop.
Example of an Implementation for onMessageReceived
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
if (null != remoteMessage)
{
if (remoteMessage.getNotification() != null)
{
// The Message contains a notification payload.
// Note, that this can only happen, when app is in FOREGROUND
// Messages that contain a notification payload DO NOT TRIGGER onMessageReceived in background
String message = remoteMessage.getNotification().getBody();
String title = remoteMessage.getNotification().getTitle();
if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0)
{
// Message contains both, data and notification payload
Map<String, String> dataPayloadkeyValueMap = remoteMessage.getData();
// [...] Process Data Payload
}
// [...] App is in foreground, Update Content
}
else if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0)
{
// "Silent" Notification (contains only a data payload)
// This will happen even if the app is in background or not running
Map<String, String> dataPayloadkeyValueMap = remoteMessage.getData();
// [...] Process data
// [...] Can Schedule a local push here, if the user needs to be informed about anything
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment