我发现自己很好奇为什么 Notification.Builder 上的 setLargeIcon 方法只接受位图,而没有提供资源 id 的重载。也许这是出于性能原因,但 setSmallIcon 确实接受 res drawable id 似乎很奇怪。
Notification.Builder builder = new Notification.Builder(application);
// ....
builder.setLargeIcon(iconBitmap); // Requires a Bitmap
builder.setSmallIcon(iconResId); // Requires a drawable resource ID
Notification notification = builder.getNotification();
遗憾的是,提供的位图未在通知中缩放,因此需要为通知视图提供正确大小的位图。
假设我需要提供 xhdpi、hdpi、mdpi 和 ldpi 版本的 largeIcon 位图,它们需要多大的尺寸?在文档中或在搜索更广泛的网络之后,我看不到任何提及。