I am trying to start a foreground service in my app. I was informed that there needs to be a notification whenever a service is started for api level 28 and above. Below is the code I used within onstartcommand of my service class
Intent notif=new Intent(this,MyService.class);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,notif,0);
Notification notification=new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentText("w")
.setContentTitle("jj")
.setContentIntent(pendingIntent).build();
startForeground(200,notification);
When I do this I receive error
Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=My channel pri=0 contentView=null
I have seen posts relating to this such as Bad notification for start Foreground, Invalid channel for service notification: but they all contain a checking for android version 26 and above. What is the best way to handle this error given my min sdk version is 16 and maximum sdk version is 28. This is the first time I am working with services and notifications
This my first time working with services and notifications.