本文介绍了如何使用Android支持库23.2将vectorDrawable用作推送通知的图标? setSmallIcon给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用受API< v21,因此我使用Android支持库23.2来管理我的vectorDrawables.
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));
我遇到了错误:
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)
在这种情况下如何使用vectorDrawable?可能吗?
How can I use vectorDrawable in this case? Is it possible at all?
推荐答案
否,VectorDrawables只能在Android 5.0+设备上的应用程序外部发送-该框架不知道在此之前如何处理vector drawables.
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.
这篇关于如何使用Android支持库23.2将vectorDrawable用作推送通知的图标? setSmallIcon给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!