Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use vectorDrawable as icon for push notifications using Android Support Library 23.2? setSmallIcon gives error

My app is under API < v21, so I use Android Support Library 23.2 for managing my vectorDrawables.

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

All views works ok exept icon for push notification:

NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setColor(getResources().getColor(R.color.colorAccent))
                        .setSmallIcon(R.drawable.ic_play_arrow_white_24dp) //ERROR
                        .setContentTitle(getString(R.string.app_name))
                        .setContentText(getString(R.string.playing));

I've got the error:

    E/AndroidRuntime: FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification posted from package com.ashomok.lullabies: Couldn't create icon: StatusBarIcon(pkg=com.ashomok.lullabiesuser=0 id=0x7f020053 level=0 visible=true num=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

How can I use vectorDrawable in this case? Is it possible at all?

like image 575
Yuliia Ashomok Avatar asked Dec 19 '22 16:12

Yuliia Ashomok


1 Answers

No, VectorDrawables can only be sent outside your app on Android 5.0+ devices - the framework does not know how to handle vector drawables prior to that.

like image 75
ianhanniballake Avatar answered Apr 29 '23 13:04

ianhanniballake