15

I am able to create notification so:

 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 if (notificationManager != null) {
     notificationManager.notify(NOTIFICATION_ID, notification);
 }

and so:

 NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(MainActivity.this);
 notificationManagerCompat.notify(NOTIFICATION_ID, notification);

So, what differences between these ways?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • If you check the source code of `NotificationManagerCompat` it is using `NotificationManager` behind the scene. – Enzokie Sep 30 '18 at 08:19
  • See this answer for a similar question: [Does NotificationManagerCompat only have wear-specific features in relation to NotificationManager?](https://stackoverflow.com/questions/50192724/does-notificationmanagercompat-only-have-wear-specific-features-in-relation-to-n/52575832#52575832) – Itamar Kerbel Sep 30 '18 at 09:47

1 Answers1

6

NotificationManagerCompat is a compatibility library for NotificationManager with fallbacks for older platforms.

I encourage you to take a look at the NotificationManagerCompat class since there are many different adjustments.

Generally almost all functions in NotificationManagerCompat call a compatible function in the NotificationManager.

For example function NotificationManagerCompat.notify() check for a flag EXTRA_USE_SIDE_CHANNEL. If it is false - the function simply calls NotificationManager.notify(). If set to true, the posted notification should use the side channel for delivery instead of using notification manager(Maximum sdk build version which needs support for side channeled notifications is API 19).

Hadas
  • 906
  • 12
  • 22