我尝试使用下面的代码在通知栏中仅添加一张图片,并在状态栏中设置smallIcon图片
notification.setSmallIcon(R.drawable.badge); //foreground png image
notification.setColor(getResources().getColor(R.color.ic_launcher_background)); // background png image(red)
请参考上面的图片,我想知道如何在通知中设置第二张图片。
最佳答案
根据定义,setLargeIcon(Bitmap bitmap)
接受Bitmap
或重载实现setLargeIcon (Icon icon)
接受Icon
实例。
Notification.Builder setLargeIcon(位图b)
如下设置大图标。
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setContentTitle("Title")
.setContentText("Hi")
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
对于Android的App tagetting。
NotificationCompat.Builder(Context context)
已被弃用。您必须使用具有channelId参数的构造函数,请参见Documentation:NotificationCompat.Builder(上下文上下文,字符串channelId)