android - 通知图标显示不正确

标签 android push-notification

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

Status bar

我的消息服务看起来像这样:

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());
}

我用 this 生成了小图标(非常棒)工具,正如您所见,Android Studio 能够找到所需的各种尺寸的图像:

enter image description here

这是我的 SDK 版本:

used sdk versions

我之前读到缓存可绘制对象可能存在一些问题,我已经尝试使每个缓存无效并清理/构建项目。 我还尝试了不同的图像文件以及 xml 矢量绘图。

你们知道我做错了什么或者我该如何进一步解决问题吗?

提前致谢!

编辑:

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

enter image description here

最佳答案

您在每个文件夹中都有相同的 Logo 名称,可能通知所需的 Logo 名称不同,因为通知图标必须为 24x24 dp

关于android - 通知图标显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50216454/

相关文章:

android - 我想通过通知停止主要 Activity

ios - iOS推送通知-播放两个音频文件

c# - 用于获取通知的通用 Windows 10 应用程序后台任务计时器

ios - 如何提取推送通知的部分内容?

android - 单击取消按钮上的日期选择器对话框时如何完成 Activity

android - 其他选项菜单项在展开的搜索 View 折叠后不显示

android - 如何在 Android 应用程序中从当前屏幕转到上一个屏幕

android - RxJava-发出新项目时如何停止正在运行的任务

android - ionic + Cordova : How to receive the push notifications after the system reboot?

android - 将单个项目对齐到 RecyclerView android 中的中心