通知图标不显示应用程序图标,此问题仅在android 12中出现。
我的代码:-通知方法:-
Intent intent = new Intent(this, FragmentController.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
/*PendingIntent.FLAG_ONE_SHOT*/ PendingIntent.FLAG_IMMUTABLE);
String channelId = "Notification channel ID";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.logo_round)
//.setSmallIcon(R.mipmap.ic_launcher_new_logo_round) //<- this not working
.setLargeIcon(BitmapFactory.decodeResource(PushNotificationService.this.getResources(),R.drawable.logo_round))
.setContentTitle(Title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
Android清单文件:-(在应用程序标记下)
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/logo_round" />
这些答案没有帮助:Android Push Notifications: Icon not displaying in notification, white square shown instead
以及
如何将应用图标设置为通知抽屉中的通知图标
1条答案
按热度按时间i86rm4rw1#
你在这里看到的是你的应用程序图标(我猜是圆形的),没有所有花哨的颜色,显示在一个蓝色的圆形。
下面是一个透明图标的样子,它有一个蘑菇的形状(我想这会帮助你理解我的意思)
您的通知图标必须是一个简单的形状,单一的颜色,和一个透明的背景(就像你可以看到你的屏幕截图)
我会更新我的答案与官方文件和基调,只要我找到它。