Search code examples
javaandroidpush-notificationandroid-5.0-lollipopandroid-notifications

Android small notification icon not showing in 5.1 (LOLLIPOP)


I have implemented Push notification and it it's working fine but when I receive the notification small notification icon is not showing on LOLLIPOP and Large icon is showing fine and on the status bar when I receive the notification a square box is showing on on LOLLIPOP i will post my code , my small notification icon image and my code, please any one guide me .

public void sendNotification(Context context,String message, String action) {
        try {
            int icon = R.drawable.notilogoboss;
            String title = context.getString(R.string.app_name);

            Intent intent = new Intent(context, MainActivity.class);
            intent.putExtra("message", message);
            intent.putExtra("action", action);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);

            PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logoboss))
                    .setSmallIcon(icon)
                    .setContentTitle(title)
                    .setWhen(System.currentTimeMillis())
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                    .setContentIntent(pendingIntent);

            NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
            int notId = UUID.randomUUID().hashCode();
            notificationManager.notify(notId, notificationBuilder.build());

        } catch (Exception e) {
        }
    }

[![enter image description here][1]][1] enter image description here


Solution

  • As noted in Android 5.0 Behavior Changes of the Android Developers site under Notifications:

    Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. Make sure that all your notifications look right with the new color scheme. If your notifications look wrong, fix them:

    Use setColor() to set an accent color in a circle behind your icon image. Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

    http://developer.android.com/about/versions/android-5.0-changes.html.