Q:

How to add animated icon to contentView of download notification?

I know I could have animated download icon in status bar when downloading a file by using the default android resource android.R.drawable.stat_sys_download. My question is how to have this animated icon in the contentView of download notification? Like when you are downloading a file with Chrome.

I attempted to display the resourse using ImageView but it does not support animated icons and the icon was displayed like an ordinary icon with no animations.

A:

I found the solution. You should use notification styling. Icon is one of the major components in the notification which android sets its style. So in addition to use android.R.drawable.stat_sys_download as icon resource, you should use .setStyle even if you have custom notification layout.
    mBuilder = new NotificationCompat.Builder(context, channelID)
            .setCustomContentView(collapsedView)
            .setColor(context.getResources().getColor(R.color.colorPrimary))
            .setSmallIcon(android.R.drawable.stat_sys_download)
            .setOngoing(true)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setPriority(NotificationCompat.PRIORITY_LOW);

