【发布时间】:2015-08-28 00:18:26
【问题描述】:
我的应用生成通知,但我为该通知设置的图标没有显示。相反,我得到一个白色方块。
我已尝试调整图标的 png 大小(尺寸 720x720、66x66、44x44、22x22)。奇怪的是,当使用较小的尺寸时,白色方块会更小。
我已经用谷歌搜索了这个问题,以及生成通知的正确方法,从我阅读的内容来看,我的代码应该是正确的。可悲的是,事情并非如此。
我的手机是装有 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);
}
【问题讨论】:
-
解决了这个问题吗?我仍然面临同样的问题,如果我添加透明图像,在顶部状态栏中仍然显示通知的空白区域
-
是的,我通过创建透明图标或针对 SDK 20 或更低版本来修复它。如果这不能为您解决问题,那么您的类似问题可能有不同的原因。我建议将目标 SDK 版本设置为 20 并检查这是否有任何改变。如果没有,不确定这个问题是否可以帮助你:(
标签: android push-notification notifications firebase-cloud-messaging icons