Guest User

Untitled

a guest
Feb 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package com.example.csanchez.pushexample;
  2.  
  3. import android.util.Log;
  4.  
  5. import com.google.firebase.messaging.FirebaseMessagingService;
  6. import com.google.firebase.messaging.RemoteMessage;
  7.  
  8. /**
  9. * Created by csanchez on 11/02/18.
  10. */
  11.  
  12. public class MyFirebaseMessagingService extends FirebaseMessagingService {
  13.  
  14. private static final String TAG = "MyFirebaseMsgService";
  15.  
  16. /**
  17. * Called when message is received.
  18. *
  19. * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
  20. */
  21. // [START receive_message]
  22. @Override
  23. public void onMessageReceived(RemoteMessage remoteMessage) {
  24.  
  25. if(remoteMessage == null){
  26. return;
  27. }
  28.  
  29. Log.d(TAG, "From: " + remoteMessage.getFrom());
  30. if (remoteMessage.getData().size() > 0) {
  31. Log.d(TAG, "Message data: " + remoteMessage.getData());
  32. }
  33.  
  34. if (remoteMessage.getNotification() != null) {
  35. Log.d(TAG, "Message Body: " + remoteMessage.getNotification().getBody());
  36. }
  37.  
  38. ((PushExampleApplication) getApplication())
  39. .bus()
  40. .send(new MyNotification(remoteMessage.getNotification().getTitle(),
  41. remoteMessage.getNotification().getBody()));
  42. }
  43. }
Add Comment
Please, Sign In to add comment