10

I have been getting a blank/grey notification icon on some Android devices (Pixel 2 XL and Pixel 5 - both Android 11), but it shows up fine on other Android devices I tested on (Huawei P20 & P30 - both Android 10). Has anyone else come across this anomaly?

This is what I tried:

private fun sendNotification(title: String?, message: String?, intent: Intent) {
    val pendingIntent = PendingIntent.getActivity(
        this,
        0 /* Request code */,
        intent,
        PendingIntent.FLAG_ONE_SHOT
    )

    // With the default notification channel id the heads up notification wasn't displayed
    val channelId = getString(R.string.heads_up_notification_channel_id)
    val notificationBuilder =
        NotificationCompat.Builder(this, channelId).setSmallIcon(R.mipmap.ic_stat_ic_notification)
            .setAutoCancel(true)
            .setColorized(true)
            .setColor(ContextCompat.getColor(this, R.color.color_orange))
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_MAX)
            .setContentIntent(pendingIntent)


    if (title != null) {
        notificationBuilder.setContentTitle(title)

    }

    if (message != null) {
        notificationBuilder.setContentText(message).setStyle(
            NotificationCompat.BigTextStyle()
                .bigText(message)
        )
    }

    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(
            channelId,
            "Test",
            NotificationManager.IMPORTANCE_HIGH
        )
        notificationManager.createNotificationChannel(channel)
    }

    notificationManager.notify(Random.nextInt()/* ID of notification */, notificationBuilder.build())
}

enter image description here

Z-100
  • 518
  • 3
  • 19
SolidCoder
  • 174
  • 3
  • 15
  • Here is R.mipmap.ic_stat_ic_notification a image or vector? Could you try to use only png and remove all the vector reference and see if this fixes the issue – AndroidEngineX Nov 30 '20 at 07:28
  • I too face the same issue.. in my case i use "cordova-plugin-fcm-with-dependecy-updated" plugin, the notification icon is mapped to '@mipmap/ic_launcher.' Have you found the solution? – Sarath May 05 '21 at 03:45

2 Answers2

0

I tested on android 9, 10, 11. It works fine.

In android studio:

  • Select image asset
  • Click icon type

Both options worked perfectly fine for me. LMK

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scrolling)
              sendNotification("Hello","thinking of refering friend?",intent);
        }


    private fun sendNotification(title: String?, message: String?, intent: Intent) {
        val pendingIntent = PendingIntent.getActivity(
                this,
                0 /* Request code */,
                intent,
                PendingIntent.FLAG_ONE_SHOT
        )

        // With the default notification channel id the heads up notification wasn't displayed
        val channelId = getString(R.string.heads_up_notification_channel_id)
        val notificationBuilder =
                NotificationCompat.Builder(this, channelId).setSmallIcon(R.drawable.abcd)
                        .setAutoCancel(true)
                        .setColorized(true)
                        .setColor(ContextCompat.getColor(this, R.color.color_orange))
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setContentIntent(pendingIntent)


        if (title != null) {
            notificationBuilder.setContentTitle(title)

        }

        if (message != null) {
            notificationBuilder.setContentText(message).setStyle(
                    NotificationCompat.BigTextStyle()
                            .bigText(message)
            )
        }

        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel = NotificationChannel(
                    channelId,
                    "Test",
                    NotificationManager.IMPORTANCE_HIGH
            )
            notificationManager.createNotificationChannel(channel)
        }

        notificationManager.notify(Random.nextInt()/* ID of notification */, notificationBuilder.build())
    }
}
Z-100
  • 518
  • 3
  • 19
0

I have had a similar Issue before. In my case the problem was the icon that I tried to use. I used a non-PNG file for the icon of the notification. When I switch it to PNG format, the nofication worked normally for all devices I tested.

If you are not using Png format for the icon , you can try this way.

Also, the problem can be the size of your icon in android reference website it is stated that

Set the small icon to use in the notification layouts. Different classes of devices may return different sizes.

Also see this guiadeline for Keyline Shapes

Oğuzhan Aslan
  • 166
  • 2
  • 10