Karthikkumar
Karthikkumar

Reputation: 87

How to set custom notification icons from URL image Nougat and above OS Version?

I have implemented the custom icons by image URL in notification which is achieved by getting default remote views using below code

RemoteViews contentView = notification.contentView;
                RemoteViews bigContentView = notification.bigContentView;
                int bigIconId = context.getResources().getIdentifier("android:id/big_picture", null, null);
                int iconId = context.getResources().getIdentifier("android:id/icon", null, null);
                int smallIconId = context.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
                int largeIconExId = context.getResources().getIdentifier("profile_badge", "id", android.R.class.getPackage().getName());
                if (finalSmallIcon != null)
                    Picasso.with(context).load(finalSmallIcon).into(contentView, iconId, finalData_id, notification);
                if (finalLargeIcon != null) {
                    Picasso.with(context).load(finalLargeIcon).into(contentView, iconId, finalData_id, notification);
                    Picasso.with(context).load(finalLargeIcon).into(contentView, largeIconExId, finalData_id, notification);
                }
                if (finalSmallIcon != null)
                    Picasso.with(context).load(finalSmallIcon).into(contentView, smallIconId, finalData_id, notification);

                if (finalBigPicture != null) {
                    //  Picasso.with(context).load(finalLargeIcon).into(bigContentView, iconId, finalData_id, notification);
                    Picasso.with(context).load(finalBigPicture).into(bigContentView, bigIconId, finalData_id, notification);
                }
            }
        });

But in Nougat and Above getting null in from "notification.contentView". So how can i update the notifications icon in Nougat and above with customLayout and RemoteView class. Thanks in advance.

Upvotes: 1

Views: 743

Answers (1)

Karthikkumar
Karthikkumar

Reputation: 87

    NotificationCompat.Builder notificationBuilder = new notificationCompat.Builder(context);
        notificationBuilder
                .setSmallIcon(context.getApplicationInfo().icon);
        notificationBuilder.setLargeIcon(largeIcon != null &&!largeIcon.isEmpty()? Picasso.with(context).load(largeIcon).get() : BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));

Upvotes: 1

Related Questions