簡體   English   中英

如何使用Android支持庫23.2將vectorDrawable用作推送通知的圖標? setSmallIcon給出錯誤

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

我的應用程序在API <v21下,因此我使用Android支持庫23.2來管理我的vectorDrawables。

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

所有視圖都可以正常執行推送通知的圖標:

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? 有可能嗎?

不,VectorDrawables只能在Android 5.0+設備上的應用程序之外發送 - 框架在此之前不知道如何處理矢量繪圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM