简体   繁体   English

推送通知图标显示为灰色

[英]Push Notifications icon displaying gray color

In my app Firebase push notification not displaying icon properly, It showing total gray color icon in notification. 在我的应用程序Firebase推送通知中无法正确显示图标,它在通知中显示了总的灰色图标。 Code I using for implementing notifications 我用于实现通知的代码

var notificationBuilder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.ic_launcherLmg)
.SetContentTitle(user.Organization)
.SetSubText(user.ModuleName)
.SetContentText(user.BodyText)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent)
.Build();

Icon I am setting at SetSmallIcon(Resource.Drawable.ic_launcherLmg) line. 我正在SetSmallIcon(Resource.Drawable.ic_launcherLmg)行设置的图标。 ic_launcherLmg icon is available in below folders wtih given dimensoins ic_launcherLmg图标位于以下文件夹中,并带有dimensoins

  1. drawable-idpi--36x36 drawable-idpi--36x36
  2. drawable-mdpi--48x48 drawable-mdpi--48x48
  3. drawable-hdpi--72x72 drawable-hdpi--72x72
  4. drawable-xhdpi--96x96 drawable-xhdpi--96x96

App targating Highest 8.1 API. 应用包含最高8.1 API。 Minimun 5.0 API. Minimun 5.0 API。

Screenshot of push notification 推送通知的屏幕截图

在此处输入图片说明

Maybe your icon is not showing with background fcm push? 也许您的图标没有通过背景fcm推送显示? So you need to put this inside application tag inside manifest as described here here : 因此,你需要在此描述放在这里面的应用程序标签中体现在这里

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_launcherLmg" />

Android displays this custom default icon for all notification messages where the notification icon is not explicitly set. 对于未明确设置通知图标的所有通知消息,Android都会显示此自定义默认图标。

You can use 您可以使用

Use a mipmap icon instead of a drawable icon and put it in xxxhdpi-mipmap folder. 使用mipmap图标而不是可绘制图标,然后将其放在xxxhdpi-mipmap文件夹中。 The icon will automatically adjust its color if the background is white 如果背景为白色,图标将自动调整其颜色

or 要么

Use notification icon as android version like 使用通知图标作为android版本,例如

.SetSmallIcon(getNotificationIcon())

and the function is or change it as you want 功能是或根据需要更改它

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher;
}

Finally this issue solved by changing the color of icon. 最后,通过更改图标的颜色解决了该问题。 Whatever the content of notification icon we want to show that should be in Gray color & background of icon should be White . 无论我们要显示的通知图标的内容为Gray ,图标的背景应为White Example image 范例图片

在此处输入图片说明

I did not notice size concern, however the preferred size should be 我没有注意到尺寸问题,但是首选尺寸应该是

  • mdpi (160 dpi) 24 x 24 px mdpi(160 dpi)24 x 24像素
  • hdpi (240 dpi) 36 x 36 px hdpi(240 dpi)36 x 36像素
  • xhdpi (320 dpi) 48 x 48 px xhdpi(320 dpi)48 x 48像素
  • xxhdpi (400 dpi) 60 x 60 px xxhdpi(400 dpi)60 x 60像素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM