7

I am using the below snippet to generate notifications in my android app.

private void sendNotification(String contentText, String message) {

    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("clear","clear");
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
     Intent.FLAG_ACTIVITY_CLEAR_TASK);

   PendingIntent piResult = PendingIntent.getActivity(this, 0, resultIntent,0);

    NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
            .setContentTitle("title")
            .setContentText(message)
            .setAutoCancel(true)
            .setLargeIcon(BitmapFactory.decodeResource(getResources() 
            ,R.drawable.notification))
            .setContentIntent(piResult);

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);

    int i;
    for(i=0; i<messageList.size();i++){
        notification.addLine(messageList.get(i));
    }
    notification.setBigContentTitle("title");
    notification.setSummaryText(contentText);

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID,notification.build());
}

It works in android 5 and 6 but for android nougat it is not working

3 Answers 3

3

Following the docs from the Android API:

Status bar icons are composed simply of white pixels on a transparent backdrop, with alpha blending used for smooth edges and internal texture where appropriate.

Your whole image but the transparent parts is going to be converted to white (being originally white or having colors).

One solution is to create a silhouette icon with color, by this way you can use the same image in all Android APIs. One example could be this icon:

White image on a transparent backdrop

In lower versions of Android you would see the black face, in the last versions you will see the same face but with white color. That's because of the transparent parts (it seems SO removes the transparency, you can get the original from here) of the image.

2

From android version lollpop onwards, they have made the changes for the notifications. When you are specifing the small icon, it should be of specific size as mentioned in this link.

The important thing is the image should be transparent and contains only white color.

You can check this question to get the answer

3
  • The image is transparent only Mar 29, 2017 at 11:25
  • 1
    @SureshKumar Your image probably have a transparent background but the icon is a square so you get a squared white image. Your whole image except the transparent parts will be converted to white. Mar 29, 2017 at 11:39
  • @AlbertoMéndez Thanks I will check that out Mar 29, 2017 at 11:51
1

According to this blog here

It says that

You’ll note that the icons are not present in the new notifications; instead more room is provided for the labels themselves in the constrained space of the notification shade. However, the notification action icons are still required and continue to be used on older versions of Android and on devices such as Android Wear.

If you’ve been building your notification with NotificationCompat.Builder and the standard styles available to you there, you’ll get the new look and feel by default with no code changes required.

2
  • yeah but its weird that the notification doesnt popup with the icon though :/ Mar 29, 2017 at 11:37
  • actually it's their redesign of notification, which allows direct reply and so on. Mar 29, 2017 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.