How to Set The App Icon as The Notification Icon in The Notification Drawer

How to set the app icon as the notification icon in the notification drawer

Try this code at your notification builder :

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

android.app.NotificationManager notificationManager =
(android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Set Large icon does the trick.Comment below if you have any further info

App uses the Launcher Icon as Notification Icon on some phones

setSmallIcon() is used to set the icon in the status bar as said in the documentation.

If you want to set the icon in the notification drawer, add setLargeIcon() to your Notification.Builder:

.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.map_not))

App icon isnt showing on notification bar

Following the API reference of the location library you are using, we can find the method you use to set the notification. Check the docs here.

You need to provide the iconName, as per the documentation:

searches for a drawable resource with the given iconName. If no matching resource is found, no icon is shown.

Since it says "drawable", I would say you need to use the drawable folder on the android folder only, not the assets.

Setting push notification icon for various Android OS versions

  1. Because they allowed certain time lapse for developers to update their apps. This time ran out when Android 7 was launched. However, while in those phones you may see the colored icon on the notification bar, you are surely getting a white icon contour only in the detailed notification panel (starting w/Android 5)

  2. You can't. You should use a white icon with PNG transparency together with the color push payload value to get the white icon with your colored background in the detailed notifications panel.

  3. I guess they stopped supporting this because developers tend to create extremely ugly icons, which in small size (18x18 or so) look even worse. In this case it's better to see the icon contour only, also more aesthetically consistent... this is more reasonble than asking developers to design icons with the same style and guidelines. The key here is to have a proper logo, simple but unique, without much detail. Consider the "f" icon from Facebook, or the envelope from Gmail: those icons can always be identified and associated withe the corresponding app even in monochrome palette. If your logo needs a 256x256 resolution to fit all its detail, it's time to call a graphic designer to create a new logo.

  4. The only way to show different icons for different Android versions, is to change the icon payload on the server side before sending the push. You can (and should) save the Android OS version together with your push registration ID for each user. However, I wouldn't recommend you to proceed with this idea of different icons because:

    • The icon will be wrongly shown in the notification detail starting Android 5
    • You are generating style inconsistency between users and devices.
    • Your goal should be the exact opposite; to make sure all users and all devices get to see the same icon in the same style.

Regarding that last point, users in Android 4 won't see the bg color you set in your push, they'll see the PNG transparency icon with the default black background.

I hope my post threw some light to all your push icon doubts, let me know otherwise.

How to Change the Android Notification Icon/Status Bar Icon for Push-notification in #flutter?

Just add a meta-data inside tag in your manifest file.

Reference

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->

<application
android:name="io.flutter.app.FlutterApplication"
android:label="When Coin"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_stat_ic_notification" />

NOTE: Before starting, make sure your icon/image has a transparent background. The solution will seem like it's not working if your image background has a color.

Want to generate mipmap icons, try appicon.co/



Related Topics



Leave a reply



Submit