Thursday 26 November 2020

Android notification icon is blank on some devices

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



from Android notification icon is blank on some devices

No comments:

Post a Comment