我的应用会生成通知,但我没有显示为该通知设置的图标.相反,我得到一个白色方块.
我已经尝试调整图标的大小(尺寸720x720,66x66,44x44,22x22).奇怪的是,当使用较小尺寸时,白色方块较小.
我已经google了这个问题,以及生成通知的正确方法,从我读过的代码应该是正确的.可悲的是,事情并不像他们应该的那样.
我的手机是带有Android 5.1.1的Nexus 5.问题还出现在模拟器,带有Android 5.0.1的三星Galaxy s4和带有Android 5.0.1的摩托罗拉Moto G上(我借用了这两款,现在还没有)
接下来是通知代码和两个屏幕截图.如果您需要更多信息,请随时提出要求.
谢谢你们.
@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification;
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.lg_logo)
.setContentTitle(title)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setContentText(msg)
.setContentIntent(contentIntent)
.setSound(sound)
.build();
notificationManager.notify(0, notification);
}
Run Code Online (Sandbox Code Playgroud)

我已经创建了抬头通知。如下所示,
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, channelId)
.setContentTitle("Message")
.setContentText("Recieved Successfully")
.setContentIntent(pendingIntent)
//.setColor(ContextCompat.getColor(this, R.color.green))
.setSmallIcon(R.drawable.notification_icon)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH);
manager.notify(m,notification.build());
Run Code Online (Sandbox Code Playgroud)
上面的代码放置在一个名为 NotificationService 的类中,该类扩展了 Service。
我可以使用下面的代码设置颜色,
setColor(ContextCompat.getColor(this, R.color.colorAccent))
Run Code Online (Sandbox Code Playgroud)
但是使用它只能设置唯一的颜色。
**我的目标不是那样。我想用它的原始颜色设置我的图标,就像在 Dominos 中一样。
在Android Manifest中添加了以下代码,
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
Run Code Online (Sandbox Code Playgroud)
当我收到推送通知时,我正在启动我的服务以显示如下所示的通知, startService(new Intent(this,NotificationService.class));
但是我收到了灰色的通知图标,而不是原始颜色。还搜索了很多网站和堆栈问题。但是关于这个问题的答案是我上面提到的在Android Manifest中放置通知图标的代码。尽管我遵循了答案,但无法将通知图标设置为多米诺骨牌。我没能找到哪里出错了。搜索了大部分发布的堆栈问题。但无法为我的问题找到合适的答案。

任何人请帮助我...
以下是我收到的通知。
如您所见,我的通知图标由两个文本组成。这两个包含两种不同的颜色。这就是我正在努力实现的目标。但我只得到灰色。设置颜色只会为 h 和 m 设置一种独特的颜色。我不想要那个。
这个没有解决办法吗??没有人做到这一点??
android push-notification firebase heads-up-notifications firebase-cloud-messaging