1

I have Used targetSdkVersion 26 & Notification Icon is not displaying . When I changed to targetSdkVersion 20 it's working correctly. But when I am uploading the app to play store it's not downgrading. How can I show icon in targetSdkVersion 26. Notification small icon 72X72, Notification home screen icon

Rakesh
  • 71
  • 3
  • 12
  • 1
    for that you have to create new white transparent icon logo of your app and you have to compare version and add icon as small icon at run time – Jay Thummar May 31 '18 at 07:41
  • What is the resolution of the icon and show me some code snippet – Rakesh May 31 '18 at 07:43
  • you can refer this answer https://stackoverflow.com/a/30795471/7348352 – vikas singh May 31 '18 at 07:45
  • Ya according to answer only I followed but after 8.0 comparing also it is not showing. Below is my code – Rakesh May 31 '18 at 07:47
  • if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { b.setSmallIcon(R.mipmap.cp_logo); b.setColor(getResources().getColor(R.color.colorPrimary)); } else { b.setSmallIcon(R.mipmap.cp_logo); } – Rakesh May 31 '18 at 07:47

2 Answers2

2

Here i use the size of icon

mipmap-mdpi : 24*24
mipmap-hdpi : 36*36
mipmap-xhdpi : 48*48
mipmap-xxhdpi : 72*72

and I have store it into mipmap named as logo_white.png so while building a notification you can use this like

 notificationBuilder.setSmallIcon(getNotificationIcon())...


notificationBuilder = new NotificationCompat.Builder(this, "default")
                .setSmallIcon(icon)
                .setContentTitle(getResources().getString(R.string.app_name))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(data.get("message")))
                .setContentText(data.get("message"))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
                .setContentIntent(pendingIntent)
                .setPriority(Notification.PRIORITY_MAX);

Here is the method

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.mipmap.logo_white : R.mipmap.app_icon;
}

Here app_icon is normal app icon and logo_white is white transparent app icon

Jay Thummar
  • 1,927
  • 1
  • 11
  • 18
  • I have edited logo check in question added logo in question,still it's not showing – Rakesh May 31 '18 at 10:04
  • I have added a new code in answer as I use while building a notification ,check and try again and let me know if you get any issues – Jay Thummar May 31 '18 at 10:10
  • image icon you have created is not Proper ... the text CP should be transparent – Jay Thummar May 31 '18 at 10:25
  • How to create a transparent icon is there any tool to create. – Rakesh May 31 '18 at 10:26
  • But is working fine for targetSdkVersion 20 when i change 26 the problem i am faceing. – Rakesh May 31 '18 at 10:27
  • after marshmallow there is a change in notification icon pattern as you can see if image icon is not vector then it will display the color you have provided at a time of notification builder so if you create an vector icon in which the text CP should be transparent so it will get that color and fill your CP text and rest of the area is cover by the image so it will look like your app logo – Jay Thummar May 31 '18 at 10:33
  • Yes Its Coming,Thanks Jay. The probelm the transparent image. – Rakesh May 31 '18 at 10:39
2

easy way to set notification you should right click on drawable or your mipmap folder and choose image asset and set icon type notification Icon and choose your transparent image notification.

Thanks.

yousef A.b
  • 51
  • 1
  • 9