Nolesh Nolesh - 3 months ago 14
Android Question

Using new notification of Android v23 in older version

I know there are a lot of questions like mine, but I really need to solve it. As far as I know in API level 23 , Android has introduced new method to setSmallIcon using bitmap. So, I can use

Bitmap
to set it in notification. The reason why I can't use
Drawables
as well as
RemoteViews
is no possibilies to have resources in my library(JAR). All icons and bitmaps are stored in
Base64
format(They are small). Is there a quick way to add new
setSmallIcon
implementation to older version of Notification. Thanks.

Answer

Is there a quick way to add new setSmallIcon implementation to older version of Notification.

Not only is there no quick way, there is no way at all.

API 23 introduced a new Icon class which can be supplied to Notification.Builder.setSmallIcon(Icon). This object can be created from

  • Bitmap
  • URI pointing to an image
  • Image file path
  • Resource ID pointing to a drawable
  • Byte array

This Icon class is not present below API 23 and the only way to set a small icon to a notification is to use Notification.Builder.setSmallIcon(int) which takes a drawable resource ID as parameter.

Consider migrating from .jar to .aar.