我有这段代码:
Notification notif;
// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIntent(pendingIntent);
notifBuilder.setContentTitle(title);
notifBuilder.setSmallIcon(icon_resId);
notifBuilder.setContentText(ne.getCaption());
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
notifBuilder.setAutoCancel(autocancel);
notifBuilder.setWhen(System.currentTimeMillis());
notif = notifBuilder.build();
在Android 4.4中运行良好。
然而,在Android 5.0中,状态栏中显示的图标是一个白色正方形。当设备锁定时出现的新“通知主体”中显示的图标是正确的。
在http://developer.android.com/reference/android/app/Notification.Builder.html中,我没有看到关于API Level 21中通知图标的任何新信息。