Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Log.d(TAG,"RECIBE EL MENSAJE");
  2. // TODO(developer): Handle FCM messages here.
  3. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
  4. Log.d(TAG, "From: " + remoteMessage.getFrom());
  5.  
  6. // Check if message contains a data payload.
  7. if (remoteMessage.getData().size() > 0) {
  8. //Log.d(TAG, "Message data payload: " + remoteMessage.getNotification().getBody());
  9. try
  10. {
  11. Map<String, String> params = remoteMessage.getData();
  12. JSONObject object = new JSONObject(params);
  13. Log.e("JSON_OBJECT", object.toString());
  14. } catch(Exception ex){
  15.  
  16. }
  17.  
  18. if (/* Check if data needs to be processed by long running job */ true) {
  19. // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
  20. scheduleJob();
  21. } else {
  22. // Handle message within 10 seconds
  23. handleNow();
  24. }
  25.  
  26. }
  27.  
  28. // Check if message contains a notification payload.
  29. if (remoteMessage.getNotification() != null) {
  30. Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
  31. }
  32.  
  33. // Also if you intend on generating your own notifications as a result of a received FCM
  34. // message, here is where that should be initiated. See sendNotification method below.
  35. Intent intent = new Intent(this, MainActivity.class);
  36. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  37. PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
  38. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
  39. notificationBuilder.setContentTitle("FCM NOTIFICATION");
  40. notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
  41. notificationBuilder.setAutoCancel(true);
  42. notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
  43. notificationBuilder.setContentIntent(pendingIntent);
  44. notificationBuilder.setPriority(NotificationManager.IMPORTANCE_HIGH);
  45. notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
  46. NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  47. notificationManager.notify(0,notificationBuilder.build());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement