Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. private int notificationId = 1;
  2. private String GROUP_KEY_CHAT = "com.example.CHAT";
  3. private static final String CHANNEL_ID = "com.example.gummy.pushnotification";
  4. @Override
  5. public void onMessageReceived(RemoteMessage remoteMessage) {
  6. Map<String, String> data = remoteMessage.getData();
  7. String title = data.get("title");
  8. String body = data.get("body");
  9. String flag = data.get("flag"); // notification flag to categorize type of notification
  10. String receiverId = data.get("receiverId");
  11. String receiverName = data.get("receiverName");
  12.  
  13. Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  14.  
  15. Intent intent = null;
  16. assert flag != null;
  17. switch (flag) {
  18. case "2":
  19. intent = new Intent(getApplicationContext(), ViewVisitors.class);
  20. break;
  21. case "4": // reliever 1 notification
  22. intent = new Intent(getApplicationContext(), PendingRelieverRequests.class);
  23. break;
  24. case "5": // reliever 2 notification
  25. intent = new Intent(getApplicationContext(), Reliever2PendingRequests.class);
  26. break;
  27. case "6": // reliever 3 notification
  28. intent = new Intent(getApplicationContext(), Reliever3PendingRequests.class);
  29. break;
  30. case "7": // approval notification
  31. intent = new Intent(getApplicationContext(), EmployeeMainActivity.class);
  32. intent.setAction("LeaveHistory");
  33. case "8":
  34. intent = new Intent(getApplicationContext(), Chat.class);
  35. intent.putExtra(Constants.DISPLAY_NAME, receiverName);
  36. intent.putExtra(Constants.UID, receiverId);
  37. default:
  38. intent = new Intent(getApplicationContext(), LoginActivity.class);
  39. break;
  40. }
  41. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
  42. | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  43. PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410,
  44. intent, PendingIntent.FLAG_ONE_SHOT);
  45.  
  46. NotificationCompat.Builder notificationBuilder = new
  47. NotificationCompat.Builder(this, CHANNEL_ID)
  48. .setSmallIcon(R.drawable.ic_notification) // small icon
  49. .setContentTitle(title) // title
  50. .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) // set body to be expandable
  51. .setAutoCancel(true) // remove notification on tap
  52. .setGroup(GROUP_KEY_CHAT)
  53. .setGroupSummary(true)
  54. .setPriority(NotificationCompat.PRIORITY_MAX) // priority
  55. .setCategory(NotificationCompat.CATEGORY_MESSAGE) // system wide category
  56. .setContentIntent(pendingIntent); // set tap action
  57.  
  58. NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
  59.  
  60. notificationBuilder.setSound(uri); // set to default notification sound
  61. notificationManager.notify(notificationId++, notificationBuilder.build());
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement