【发布时间】:2021-02-21 08:39:22
【问题描述】:
我在某些 Android 设备(Pixel 2 XL 和 Pixel 5 - 均为 Android 11)上收到空白/灰色通知图标,但在我测试过的其他 Android 设备(华为 P20 和 P30 - 均为 Android)上显示正常10)。有没有其他人遇到过这种异常情况?
这是我尝试过的:
-
我已使用Android Asset Studio 确保所有图标大小都遵循defined bitmap densities。
-
我还将
.setColorized()方法添加到 Notification.Builder 对象,因为它以前在 代码,但这根本没有区别。我已经包括了我的 通知代码如下:
private fun sendNotification(title: String?, message: String?, intent: Intent) {
val pendingIntent = PendingIntent.getActivity(
this,
0 /* Request code */,
intent,
PendingIntent.FLAG_ONE_SHOT
)
// With the default notification channel id the heads up notification wasn't displayed
val channelId = getString(R.string.heads_up_notification_channel_id)
val notificationBuilder =
NotificationCompat.Builder(this, channelId).setSmallIcon(R.mipmap.ic_stat_ic_notification)
.setAutoCancel(true)
.setColorized(true)
.setColor(ContextCompat.getColor(this, R.color.color_orange))
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntent)
if (title != null) {
notificationBuilder.setContentTitle(title)
}
if (message != null) {
notificationBuilder.setContentText(message).setStyle(
NotificationCompat.BigTextStyle()
.bigText(message)
)
}
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
channelId,
"Test",
NotificationManager.IMPORTANCE_HIGH
)
notificationManager.createNotificationChannel(channel)
}
notificationManager.notify(Random.nextInt()/* ID of notification */, notificationBuilder.build())
}
【问题讨论】:
-
R.mipmap.ic_stat_ic_notification 是图像还是矢量?您能否尝试仅使用 png 并删除所有矢量参考,看看是否能解决问题
-
我也面临同样的问题。在我的情况下,我使用“cordova-plugin-fcm-with-dependecy-updated”插件,通知图标映射到“@mipmap/ic_launcher”。你找到解决办法了吗?
标签: android kotlin push-notification android-notifications android-assets