1

我在推送通知中添加了小图标,但仍未显示。我正在使用安卓 10 模拟器。我的图标满足使用无背景的白色并存储在 mipmap 文件夹中的要求。我在stackoverflow上尝试了一些解决方案,但仍然无法正常工作。这是我的代码

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context, CHANNEL_ID)
                .setSmallIcon(R.mipmap.ic_notification)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(pendingIntent)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setAutoCancel(true);

推送通知图标仍然像这样显示 在此处输入图像描述

我已尝试在 android manifest 上添加此代码,但仍然无法正常工作

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

我的 targetSDK 是 29

你有没有遇到过同样的问题并解决了?

4

1 回答 1

0

操作栏图标要求文件大小为基线大小 (MDPI) 的24×24 像素。但是,图像本身在图标文件中的中心不得超过22×22 像素。

图标设计必须是单色白色,#ffffff。

MDPI - 24 x 24  (drawable-mdpi)
HDPI - 36 x 36  (drawable-hdpi)
XHDPI - 48 x 48  (drawable-xhdpi)
XXHDPI - 72 x 72  (drawable-xxhdpi)
XXXHDPI - 96 x 96  (drawable-xxxhdpi)

有关更多详细信息,请查看Android 备忘单Android 官方文档

于 2020-12-30T09:27:14.303 回答