Hello Can someone advise me how to make a notification without receiving this exception: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
The code:
public void notifyThis(String text) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent notificationIntent = new Intent(this, RegisterActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
if(Build.VERSION.SDK_INT >= 26) {
//When sdk version is larger than26
String id = "channel_1";
String description = "143";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(id, description, importance);
channel.enableLights(true);
channel.enableVibration(true);//
manager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(MapsActivity.this, id)
.setCategory(Notification.CATEGORY_MESSAGE)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.screenmec))
.setContentTitle("MECTS.SA")
.setContentText(text)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build();
manager.notify(1, notification); }
else {
//When sdk version is less than26
Notification notification = new NotificationCompat.Builder(MapsActivity.this)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.screenmec))
.setContentTitle("MECTS.SA")
.setContentText(text)
.setContentIntent(contentIntent)
.build();
manager.notify(1,notification); }
NotificationManager mannager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mannager.notify(0,builder.build());
}