FCM默认图标使用无效的渐变 [英] FCM default icon uses invalid gradient

查看:102
本文介绍了FCM默认图标使用无效的渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未使用Android清单的默认FCM图标.而是使用Android标准图标. 在logcat中说:

The default FCM icon of the Android manifest is not used. Instead the Android standart icon is used. In the logcat it says:

E/FirebaseMessaging:ID为2131230849的图标使用无效的渐变.使用后备图标.

E/FirebaseMessaging: Icon with id: 2131230849 uses an invalid gradient. Using fallback icon.

默认图标仅包含一种颜色.我用多个不同的图标对其进行了测试,但始终使用Android标准图标.

The default icon only contains one color. I tested it with multiple different icons but always the Android standart icon is used.

推荐答案

更新:已由Firebase版本12.0.0修复

UPDATE: fixed by firebase in version 12.0.0

下面的错误代码已经更新,可以在8.0上很好地运行,同时防止了我原始答案中概述的错误.

The faulty code below has been updated with this and it works great on 8.0, while preventing the bug outlined in my original answer.

@TargetApi(26)
private final boolean zza(int var1) {
    if(VERSION.SDK_INT != 26) {
        return true;
    } else {
        try {
            if(this.zzb.getResources().getDrawable(var1, (Theme)null) instanceof AdaptiveIconDrawable) {
                Log.e("FirebaseMessaging", (new StringBuilder(77)).append("Adaptive icons cannot be used in notifications. Ignoring icon id: ").append(var1).toString());
                return false;
            } else {
                return true;
            }
        } catch (NotFoundException var2) {
            return false;
        }
    }
}


这不能解决问题,但是从评论中我被要求回答.这是元凶Firebase 11.8.0中的代码,并且仅在Android 8.0(API 26)上.进行此检查的原因是因为存在带有自适应图标 https://www.bleepingcomputer.com/news/mobile/android-oreo-adaptive-icons-bug-sends-thousands-of- phone-into-infinite-boot-loops/,因此此代码可以防止这种情况,但是这样做还可以防止非自适应图标正确显示


This doesnt solve the issue, but from the comments I was asked to put it as an answer. Here is the code from firebase 11.8.0 that is the culprit and only on Android 8.0 (API 26). The reason for this check is because there is an Android 8.0 notification bug with adaptive icons https://www.bleepingcomputer.com/news/mobile/android-oreo-adaptive-icons-bug-sends-thousands-of-phones-into-infinite-boot-loops/ so this code prevents that, but in doing so, also prevents non-adaptive icons from showing up properly

    @TargetApi(26)
private final boolean zzid(int var1) {
    if(VERSION.SDK_INT != 26) {
        return true;
    } else {
        try {
            Drawable var2;
            if((var2 = this.mContext.getResources().getDrawable(var1, (Theme)null)).getBounds().height() != 0 && var2.getBounds().width() != 0) {
                return true;
            } else {
                Log.e("FirebaseMessaging", (new StringBuilder(72)).append("Icon with id: ").append(var1).append(" uses an invalid gradient. Using fallback icon.").toString());
                return false;
            }
        } catch (NotFoundException var3) {
            return false;
        }
    }
}

我已经在我的logcat中注意到,我的应用程序每次通知均击中此代码两次,它会尝试根据Firebase的说明在清单中设置的可绘制通知通知,然后再次尝试将其作为启动器图标击中.即使当我将它们设为纯色可绘制图形时,它们都失败了.

I've noticed in my logcat, that my app hits this code twice per notification, it tries for my notification drawable which i set in the manifest as per Firebase's instructions, then hits it again trying to do it for the launcher icon. Both fail, even when I make them solid color drawables.

根据绍斯罗普的另一则评论,firebase团队已意识到该问题,并在进行修复,但未给出时间表.

As per another comment from southrop, the firebase team is aware of the issue and working on a fix but no timeline given.

此代码不在11.6.0及更低版本中,因此,如果您暂时确实需要此代码,请降级您的Firebase.

This code is not in 11.6.0 and lower, so if you really need this working for the time being, downgrade your firebase.

希望这可以帮助发现此帖子的其他人搜索错误

Hope this helps others who find this post searching for the error

这篇关于FCM默认图标使用无效的渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆