In our android app, we are trying to send different two types of notifications, one that stays for a longer time and uses .setFullScreenIntent parameter and one that is without setFullscreenIntent. So we created two notification compat builder vide code as given hereunder:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, MainActivity.asw_fcm_channel)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setTimeoutAfter(60000)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.addAction(action)
.addAction(action1)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(pendingIntent2, true)
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
NotificationCompat.Builder notificationBuilder1 = new NotificationCompat.Builder(this, MainActivity.asw_fcm_channel)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setTimeoutAfter(60000)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.addAction(action)
.addAction(action1)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
And now in Firebase messaging post process that is used to send the notification, we have a parameter called "tag".
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$token=$to;
$data = [
'title' =>$title,
'body' =>$msg,
'image'=>'https://mbracecloud.com/appln_enterprise/images_user/file_2022_37_46_2372744327498576956.jpg',
'uri'=>"",
'tag'=>'View Message'
];
Now based on that parameter, we tried to use tag:"View Message" as an "if" to use notificationBuilder template and tag:"Start" for using notificationBuilder1 template as specified above. But its just not working
if (tag=="View Message") {
Notification noti = notificationBuilder.build();
noti.flags = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notification_id, notificationBuilder.build());
}
if (tag=="Start") {
Notification noti = notificationBuilder1.build();
noti.flags = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notification_id, notificationBuilder1.build());
}
Shall appreciate should you guide us as how to do this