Android 7.0 notification icon appearing white square

I use the snippet below to create notifications in an 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 does not work.

+4
source share
4 answers

Starting with the lollpop version from android, they have made changes for notifications. When you specify a small icon, it should be of a certain size, as indicated in this link .

It is important that the image is transparent and contains only the color white .

,

+3

,

, ; . Android , Android Wear.

NotificationCompat.Builder , , , .

+1

docs API Android:

, - , .

, ( ).

, API Android. :

White image on a transparent background.

Android , , . - (, SO , ) .

0

Is there a way to get back to a transparent background for notifications? One of my favorite features of the previous version was not blinded by bright white notifications when I turned on my phone.

0
source

Source: https://habr.com/ru/post/1673491/


All Articles