I have implemented Firebase push notification in my project. I have got stuck in one issue, Notification icon not show in Nougat but same code display in other versions. I have search a lot and try different solutions like white icons , icons placed in mipmap folder dimension wise, same icons in drawable folders ,also tried manifest code but not getting success still show gray box in notification panel.
here is my Notification code :
private void sendNotification(String title, String msg) {
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "101";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@SuppressLint("WrongConstant")
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_MAX);
//Configure Notification Channel
notificationChannel.setDescription(msg);
notificationChannel.enableLights(true);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_app)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentTitle(title)
.setAutoCancel(true)
.setSound(defaultSound)
.setContentText(msg)
.setContentIntent(pendingIntent)
//.setStyle(style)
// .setLargeIcon(bitmap)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_MAX);
int id = (int) System.currentTimeMillis();
notificationManager.notify(id, notificationBuilder.build());
}
Manifest file
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification_app" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
I have solved my problem. Actually there is no issue with above code but issued in app icon, icon is fill with gradient background so that it always show gray in Nougat, to avoid this issue i have just replace plain icon logo without background and convert it to white icon and that it, its working !!