应用程序处于后台时,FCM推送通知显示白色方形图标而不是应用程序图标

Enc*_*rer 8 android firebase firebase-cloud-messaging firebase-notifications

我在我的Android应用程序中使用FCM来管理推送通知.当应用程序处于前台并且应用程序图标也可见(正确)时,它完全正常工作.但是当应用程序在后台运行时,我没有正确收到通知.而不是透明图标,它显示白色方形图标作为通知图标.我知道,FCM会自动处理后台操作.但我需要显示我的应用程序图标而不是那个白色图标.注意:我只使用透明图标.我也试过下面的编码

<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/rt_transparent_icon" />
    <meta-data android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@android:color/holo_blue_bright" />
Run Code Online (Sandbox Code Playgroud)

但是这些解决方案都没有对我有用.谁能告诉我该怎么做?

小智 0

我之前遇到过这个问题并这样解决:

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.LOLLIPOP);
    // LOLLIPOP or Marshmellew>>>>>>>>>>>>>>>>>>>>> KitKat or Less
    return useWhiteIcon ? R.drawable.logo_new : R.drawable.logo;
}
Run Code Online (Sandbox Code Playgroud)

然后调用这个函数setSmallIcon()

nbuilder.setSmallIcon(getNotificationIcon());
Run Code Online (Sandbox Code Playgroud)