I am using PNG image but its size is getting too big so I have to compromise with its quality. So i was thinking vectors may be the another way around ? Example will be a great help.
-
1if your PNG image is big include it in drawable-xxhdpi resourse folder and then use it! – Madhur Dec 01 '15 at 08:48
-
So the problem is your png image size to big for icon? you can just resize for different screen. You can use http://romannurik.github.io/AndroidAssetStudio/. It's help you to create icon for different sizes and densities. – Mohamad Damba Putrabangga Dec 01 '15 at 09:06
-
1I have re-sized and included it in drawable-xxhdpi and was using till now but because of lollipop update i had to create transparent image and use it with background color which deteriorated its quality even further. so is there anyway i can create colored drawablevector and use it as icon? – Rajan Kadeval Dec 01 '15 at 09:50
-
Is it for "setSmallIcon(int)", "setLargeIcon(Bitmap)" or "NotificationCompat.BigPictureStyle.bigPicture(Bitmap)" ? It is posible to raster a VectorDrawable to Bitmap, using the DrawingCache. ... but it would bring you back to the size issue, just moved from build time to run time. It would still lower the APK size, if this is your goal. You can use actual VectorDrawable for the "setSmallIcon(int)" but this will only work on Lollipop devices or higher (I tested it on Galaxy S4), missing - currently - about 60% of the market : http://developer.android.com/about/dashboards/index.html – John Apr 26 '16 at 13:16
7 Answers
VectorDrawables will only work as notification icons for versions higher than (or equal to) Android Lollipop - i.e. API 21.
I know this because I did try using .setSmallIcon(R.drawable.my_vector)
as shown in one of the other answers here, and although this works perfectly fine for API 21 and above, I got the following error for versions prior to Lollipop:
android.app.RemoteServiceException: Bad notification posted from package com.example.app: Couldn't create icon: StatusBarIcon(pkg=com.example.appuser=0 id=0x7f02005a level=0 visible=true num=0 )
There are also other answers on Stack Overflow supporting this argument:

- 1
- 1

- 19,687
- 20
- 75
- 125
Can we use VectorDrawable or VectorXML as icons for push notifications?
Yes, just call the vector drawable the standard way for notifications:
.setSmallIcon(R.drawable.my_vector)
In order to use the transparency (notification icons are only white and/or transparent), you will have to use the alpha channels when settings the colors in the vector XML, meaning #00000000 for transparent and #FFFFFFFF for white.

- 17,894
- 5
- 58
- 85
-
18I think this only works for API 21+ as I used the above, but got an error [like this](http://stackoverflow.com/questions/37333930/notification-throws-error-when-using-vector-drawables) for pre-Lollipop devices. Also, see [this](http://stackoverflow.com/a/37756967/4230345). – Farbod Salamat-Zadeh Sep 08 '16 at 03:34
-
1@FarbodSalamat-Zadeh Yes you need to check the user's SDK with a condition (if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)) – Yoann Hercouet Sep 19 '16 at 17:23
-
Yes, but see this other answer below as well (https://stackoverflow.com/a/62876054/624814). – SMBiggs Mar 08 '23 at 16:18
UPDATE 2020
Yes, it is definitely possible. But let Android Studio take care of icon creation. Otherwise you will be at risk of not supporting older Android versions (check other answers).
So how to create the right files with Android Studio:
- Right click on a file on the left side of Android studio
- New > Image Assets
- Icon Type > Notification Icons
- Select a vector image (.svg for example)
Android studio will create all the correct files needed.

- 1,017
- 10
- 17
For version < 21,
If you want to directly pass in vector drawable resource id into setSmallIcon(): No way.
For setLargeIcon() indirectly, yes. Use
VectorDrawableCompat drawable = VectorDrawableCompat.create(context.getResources(), resource id, theme);
then create Bitmap from this drawable and pass into setLargeIcon()

- 113
- 9
If you insist to use Vector drawable try converting it to bitmap :
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_vector_drawable);
mBuilder = new NotificationCompat.Builder(context)
.setLargeIcon(bitmap)
.setOngoing(!cancelable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(getNotificationIcon());
}

- 1,689
- 1
- 17
- 26
Here are you can do with Firebase Notification
add these on manifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_http" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/notification_color" />
- replace "ic_http" with your icon
- replace "notification_color" with your wanted color
The most Importing thing!
- In your icon, All path must be Vectoral!
- There must be no background area! (This is important, or it will show rectangle area with your desired color

- 2,852
- 2
- 26
- 44
Probably you should not use VectorDrawable icons in notifications if you are using vector drawable support package - you may encounter errors on pre-lollipop devices.
Check out this: Notification throws error when using vector drawables
Wuthout vector drawable support package, I didn't encounter any errors but after using it, pre-lollipop devices were unable to access the vector icon at the time of notification and threw this error:
android.app.RemoteServiceException: Bad notification posted from package com.xxx.xxx: Couldn't create icon: StatusBarIcon(pkg=com.xxx.xxxuser=0 id=0x7f020082 level=0 visible=true num=0)

- 1
- 1

- 1,452
- 1
- 18
- 27