Search code examples
androidandroid-notifications

When adding notification action, what is icon used for (Android)?


When adding action button you must also supply an icon https://developer.android.com/training/notify-user/build-notification

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setContentIntent(pendingIntent)
        .addAction(R.drawable.ic_snooze, getString(R.string.snooze),
                snoozePendingIntent);

However the action appears without icon on the action button: enter image description here


Solution

  • icons were presented on older OS versions, on never (7+ as far as I remember) default styling of notifications changed and icons were removed... you are setting this value only for older devices and maybe some never which have custom roms (including manufacturers improvements) with icons on these buttons kept

    note that you can provide own layout for notification and add as much icons as you want, but it will never look exacly same as all other notifications (OS styling, oftenly "improved" by manufacturer)