How to show Android notifications on the screen, as well as the status bar icon?

It seems to me that this should be trivial, but I can not show the notification on the phone screen - it is displayed only in the status bar at the top.

For an example of what I want to do, here is how Facebook Messenger appears on the screen when you receive a message.

Facebook on-screen notification

Whenever I send a notification, everything it does shows a small icon in the status bar - even if I set the priority to PRIORITY_MAX. Is there any other parameter I need to make it appear on the screen instead of the status bar?

Notification Display Code:

PendingIntent contentIntent = PendingIntent.getActivity(context, nextId++, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification.Builder builder = new Notification.Builder(context) .setContentTitle(title) .setContentText(description) .setContentIntent(contentIntent) .setSmallIcon(R.drawable.ic_stat_notification) .setLargeIcon(largeIcon) .setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); if (android.os.Build.VERSION.SDK_INT >= 21) { builder.setColor(context.getResources().getColor(R.color.orange_500)) .setVisibility(Notification.VISIBILITY_PUBLIC); } Notification notification = builder.build(); notificationManager.notify(id, notification); 
+6
source share
1 answer

All things discussed, it's really a good idea to use NotificationCompat.Builder over Notification.Builder , not to mention manually creating Notification . This gives you good backward compatibility with graceful degradation (all the way to API level 4, otherwise known as "gadzooks, the old"). AFAIK, this is the only way to get some Android Wear stuff when used in conjunction with NotificationManagerCompat . And, in this case, he looks happier with the new features of Android 5.0+.

In this case, setPriority(NotificationCompat.PRIORITY_HIGH) on the NotificationCompat.Builder used with NotificationManagerCompat , you will receive a heads-up notification on Android 5.0+.

+10
source

Source: https://habr.com/ru/post/987082/


All Articles