Fixed this by using
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
instead of
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
and replacing NotificationManager with NotificationManagerCompat in corresponding method signatures.