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

查看:16
本文介绍了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) 上.进行此检查的原因是因为存在带有自适应图标的 Android 8.0 通知错误 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.

根据 southrop 的另一条评论,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天全站免登陆