Samsung S8/S5/J2/Note3 are getting Firebase Push Notification successfully either app is killed, in background or foreground,
but In
I hope the following code will work for you. Its working for me in every devices.
Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence nameChannel = context.getString(R.string.app_name);
String descChannel = context.getString(R.string.app_name);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(context.getString(R.string.app_name), nameChannel, importance);
channel.setDescription(descChannel);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
assert notificationManager != null;
notificationManager.createNotificationChannel(channel);
}
PendingIntent pendingIntent = PendingIntent.getActivity((context), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Create Notification
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, context.getString(R.string.app_name))
.setChannelId(context.getString(R.string.app_name))
.setContentTitle(TextUtils.isEmpty(title) ? getString(R.string.app_name) : title)
.setContentText(description)
.setTicker(context.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_stat_name)
.setSound(notificationSound)
.setLights(Color.RED, 3000, 3000)
.setVibrate(new long[]{500, 500})
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
if (result != null) {
notification.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(result));
}
assert notificationManager != null;
notificationManager.notify(100, notification.build());
I just have created Notification Channel, Check If condition for Oreo.
Let me know if you get any problem. I am here to help you.
Thanks.