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

戏子无情 提交于 2020-01-21 12:15:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/37756632/how-can-i-use-vectordrawable-as-icon-for-push-notifications-using-android-suppor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!