通知图标显示不正常

3

我正在尝试为我的应用程序设置一个新的通知图标,但似乎无法使其正常工作。我可以接收到通知,但在状态栏中看到的是一个黑色/灰色圆圈,如下所示:

状态栏

我的MessageService代码如下:

public class MyMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Intent intent = new Intent(this, MessageActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("notification_msg_id", remoteMessage.getData().get("my_msg_id"));

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder
            = new NotificationCompat.Builder(this)
     .setContentTitle(remoteMessage.getNotification().getTitle())
     .setContentText(remoteMessage.getNotification().getBody())
     .setAutoCancel(true)
     .setSmallIcon(R.drawable.ic_stat_my_logo)
     .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
     .setColor(getResources().getColor(R.color.colorBlack))
     .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

我使用了这个非常好用的工具生成了小图标,而且你可以看到Android Studio能够在需要的每个尺寸中找到图片:

enter image description here

以下是我的SDK版本:

used sdk versions

我之前读到过可能会出现一些关于drawable缓存的问题,所以我已经试过无效化所有缓存并清理/重建项目。我也试过不同的图片文件和XML矢量可绘制对象。

你们有什么想法,我做错了什么或者如何进一步排除问题呢?

提前致谢!

编辑:

这是我正在尝试使用的xxxhdpi-v11格式的图标(它是白色的,你可能需要点击它才能看到):

enter image description here


请发布您的图标,似乎是ic_stat_my_logo.png的问题。 - Taranmeet Singh
放置小图标,因为如果大图标不适合,则会显示黑色。 - user4571931
@AndroidTeam 所以它显示黑色是因为大图标不适合 - 不是因为小图标不适合? - Lars
@Taranmeet,我现在已经发布了图标。希望这能有所帮助。 - Lars
2个回答

0

API 21及更高版本的通知图标必须完全为白色。请尝试使用以下代码:

notification.setColor(getResources().getColor(R.color.notification_color));

将颜色更改为白色会更改模拟器上圆圈的颜色,但不幸的是它仍然没有显示图标。 - Lars

0

每个文件夹中都有相同的徽标名称,也许通知所需的那个不同,因为通知图标必须是24x24 dp。


我有24x24、36x36、48x48和72x72的尺寸,所以我不认为缺少任何尺寸。不过还是谢谢你的回答。 - Lars

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接