Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int notificationId = 1;
- private String GROUP_KEY_CHAT = "com.example.CHAT";
- private static final String CHANNEL_ID = "com.example.gummy.pushnotification";
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- Map<String, String> data = remoteMessage.getData();
- String title = data.get("title");
- String body = data.get("body");
- String flag = data.get("flag"); // notification flag to categorize type of notification
- String receiverId = data.get("receiverId");
- String receiverName = data.get("receiverName");
- Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- Intent intent = null;
- assert flag != null;
- switch (flag) {
- case "2":
- intent = new Intent(getApplicationContext(), ViewVisitors.class);
- break;
- case "4": // reliever 1 notification
- intent = new Intent(getApplicationContext(), PendingRelieverRequests.class);
- break;
- case "5": // reliever 2 notification
- intent = new Intent(getApplicationContext(), Reliever2PendingRequests.class);
- break;
- case "6": // reliever 3 notification
- intent = new Intent(getApplicationContext(), Reliever3PendingRequests.class);
- break;
- case "7": // approval notification
- intent = new Intent(getApplicationContext(), EmployeeMainActivity.class);
- intent.setAction("LeaveHistory");
- case "8":
- intent = new Intent(getApplicationContext(), Chat.class);
- intent.putExtra(Constants.DISPLAY_NAME, receiverName);
- intent.putExtra(Constants.UID, receiverId);
- default:
- intent = new Intent(getApplicationContext(), LoginActivity.class);
- break;
- }
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
- | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410,
- intent, PendingIntent.FLAG_ONE_SHOT);
- NotificationCompat.Builder notificationBuilder = new
- NotificationCompat.Builder(this, CHANNEL_ID)
- .setSmallIcon(R.drawable.ic_notification) // small icon
- .setContentTitle(title) // title
- .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) // set body to be expandable
- .setAutoCancel(true) // remove notification on tap
- .setGroup(GROUP_KEY_CHAT)
- .setGroupSummary(true)
- .setPriority(NotificationCompat.PRIORITY_MAX) // priority
- .setCategory(NotificationCompat.CATEGORY_MESSAGE) // system wide category
- .setContentIntent(pendingIntent); // set tap action
- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
- notificationBuilder.setSound(uri); // set to default notification sound
- notificationManager.notify(notificationId++, notificationBuilder.build());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement