Android: How to adjust the largeIcon of a NotificationCompat.Builder in the bounds of the notification

102 views Asked by At

I have built a notification, but when I set the large icon, it doesn't fit to the bounds. I would set it to display as expected.

Here is the code where the notification is created:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
    .setSmallIcon(R.drawable.ic_launcher)
    .setLargeIcon(image)
    .setContentTitle(appName)
    .setContentText(message)
    .setSound(defaultSoundUri)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setContentIntent(pendingIntent);
1

There are 1 answers

0
Apurva Kolapkar On BEST ANSWER

Try using Custom layout to show Notification :

This may help you :

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);

        RemoteViews contentView = new RemoteViews(pkgName, R.layout.custom_notification);
        contentView.setImageViewResource(R.id.notification_image, appIcon);
        contentView.setTextViewText(R.id.notification_text, message);
        notification.contentView = contentView;