k have it working in case it is of use to others
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {//Build.VERSION.SDK_INT < Build.VERSION_CODES.O
System.out.println("------------------------------- older than o sdk");
Intent notificationIntent = new Intent(this, blockservice.class);
PendingIntent pendingIntent = getActivity(this, 0, notificationIntent, 0);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "name");
Notification notification = notificationBuilder.setOngoing(true)
.setContentTitle(this.getString(R.string.app_name))
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setCategory(Notification.CATEGORY_SERVICE).build();
try {
startForeground(1337, notification);
} catch (Exception e) {
e.printStackTrace();
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//Build.VERSION.SDK_INT <= Build.VERSION_CODES.S && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
System.out.println("------------------------------- 0 or highter sdk");
final NotificationCompat.Builder notification = new NotificationCompat.Builder(this,"name")
.setContentTitle("name")
.setSmallIcon(R.drawable.a)
.setOnlyAlertOnce(true)
.setOngoing(true);
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
startForeground(1334,notification.build());
}