0

I have created heads up notification in my app. In that I have used my app icon in notification also. But that didn't displayed. Instead of that getting square shape icon. Searched regarding that issue and found that above lollipop this occurs. Also found ways to create icon for above lollipop. Converted my app icon(png) to svg format. This works fine for me. I am able to get icon in my app notification. But I really confused that what I have done is a right format or not? If not what is the best way of doing that. Please any body give me a proper explanation about this.

I know to set small icon as well as large icon. I have setted my notification small icon in svg format. Thats displying in my notification perfectly...What I want to know is, setting svg format icon in notification small icon is the right way to do?

Sandhiya
  • 339
  • 2
  • 14

2 Answers2

0

this code works on all android versions :

//    builder.setContentText(msg)
            //        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            //        .setVibrate(new long[]{500, 500})
            //        .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
                    .setSmallIcon(android.R.drawable.ic_menu_upload)
           //          .setOnlyAlertOnce(true)
           //          .setOngoing(false)
           //          .setPriority(NotificationCompat.PRIORITY_DEFAULT);
mohosyny
  • 962
  • 1
  • 9
  • 19
0

if you want to make Large icon, try this.

 Bitmap icon2 = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

 NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
 bigText.bigText(textBody);

 notificationBuilder.setLargeIcon(icon2)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(pushTitle)
                    .setContentText(contentText)
                    .setStyle(bigText)
                    .setLights(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), 3000, 3000)
                    .setVibrate(new long[]{500, 500, 500, 500})
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setAutoCancel(true)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setContentIntent(pendingIntent);
S T
  • 1,068
  • 2
  • 8
  • 16
  • @S T I want to know the format of icon inside setSmallIcon() – Sandhiya Jun 16 '20 at 08:29
  • Put the PNG's in drawable resource to reference them. SVG crash in kitkat devices. – S T Jun 16 '20 at 08:41
  • @S T that is what I tried prevoiusly. By that I couldn't able to see my icon instead I seen square shape icon – Sandhiya Jun 16 '20 at 08:43
  • 1
    You have to make the Icon monochrome from setSmallIcon. That's white, too. http://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.space.trim=1&source.space.pad=0&name=ic_stat_example Put the image on the above site, and the result screen appears at the bottom of the site! It would be good if you check and put it in. Please refer to it. – S T Jun 16 '20 at 09:01
  • 1
    and also I found this. https://stackoverflow.com/a/29207365/10778405 – S T Jun 16 '20 at 09:02
  • @S T Now I am able to set notification icon properly..Thank you.. – Sandhiya Jun 17 '20 at 06:02