我的应用程序会生成通知,但我为该通知设置的图标不会显示.相反,我得到了一个白色的正方形.
我try 过调整图标的png大小(尺寸为720x720、66x66、44x44、22x22).奇怪的是,当使用更小的尺寸时,白色正方形更小.
我已经在谷歌上搜索了这个问题,以及生成通知的正确方法,从我读到的代码应该是正确的.可悲的是,事情并不像他们应该的那样.
我的手机是带有安卓5.1.1的Nexus 5.这个问题也出现在模拟器上,一款搭载安卓5.0.1的三星Galaxy s4和一款搭载安卓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);
}