Skip to content

Instantly share code, notes, and snippets.

@sab99r
Last active June 21, 2016 16:36
Show Gist options
  • Select an option

  • Save sab99r/bc8cf03bf0322d2dc91be43e4bf12849 to your computer and use it in GitHub Desktop.

Select an option

Save sab99r/bc8cf03bf0322d2dc91be43e4bf12849 to your computer and use it in GitHub Desktop.
FirebaseMessagingService extended class
public class FcmMessageService extends FirebaseMessagingService{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//onMessageReceived will be called when ever you receive new message from server.. (app in background and foreground )
Log.d("FCM", "From: " + remoteMessage.getFrom());
if(remoteMessage.getNotification()!=null){
Log.d("FCM", "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
if(remoteMessage.getData().containsKey("post_id") && remoteMessage.getData().containsKey("post_title")){
Log.d("Post ID",remoteMessage.getData().get("post_id").toString());
Log.d("Post Title",remoteMessage.getData().get("post_title").toString());
// eg. Server Send Structure data:{"post_id":"12345","post_title":"A Blog Post"}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment