I had the same problem, but I used a newer call to NotificationCompat.Builder() , which requires the channel identifier from NotificationChannel .
The notification will be displayed as heads-up only if the NotificationChannel created with the importance value NotificationManager.IMPORTANCE_HIGH :
NotificationChannel channel = new NotificationChannel("channel01", "name", NotificationManager.IMPORTANCE_HIGH); // for heads-up notifications channel.setDescription("description"); // Register channel with system NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel);
Show one-on-one notification:
Notification notification = new NotificationCompat.Builder(this, "channel01") .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle("Test") .setContentText("You see me!") .setDefaults(Notification.DEFAULT_ALL) .setPriority(NotificationCompat.PRIORITY_HIGH) // heads-up .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(0, notification);
source share