I am working chat application. I want to show custom push Notification when message receives, when app is open and closed (not destroyed or killed) notification are received, below code is working fine, but when app is killed or destroyed from background custom push notification is not received in oreo and above
Here is code I Used
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
context = getApplicationContext();
Map<String, String> data = remoteMessage.getData();
if ("message".equals(data.get("pushNotificationAction"))){
System.out.println("message");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),
0, intent, 0);
String mediatype = data.get("mediaType");
String mesageType= data.get("messageType");
String channel_id = createNotificationChannel(getApplicationContext());
mBuilder = new NotificationCompat.Builder(getApplicationContext(),channel_id)
.setSmallIcon(R.drawable.kisan_smoll_logo1)
.setCustomBigContentView(contentViewBig)
.setCustomContentView(contentViewBig)
.setContentIntent(contentIntent)
.setContentTitle(data.get("messageText"))
.setWhen(when)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationManager.IMPORTANCE_MAX)
.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}catch(Exception e){
e.printStackTrace();
}
Sending JSON from server is below:
{
"message":{
"to": "FCMID",
"data" : {
"body" : "This is a Message!",
"title" : "Notifiation Message"
"mediaType":"IMAGE",
"messageType":"chat",
}
}
}
By sending data from server custom Fcm push notification is received in android when app is open, but when app is swipe from recent notifications are not received