Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationManagerCompat vs NotificationManager

What backwards compatibility does

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

provide that I don't get from the normal

 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

They both have a notify method that worked on my tested devices (down to API level 19).

The Google sample here doesn't even use the Compat version once:

https://github.com/googlesamples/android-NotificationChannels/blob/master/Application/src/main/java/com/example/android/notificationchannels/NotificationHelper.java

like image 507
Florian Walther Avatar asked May 04 '18 14:05

Florian Walther


1 Answers

From looking at the source code for NotificationManagerCompat, the bulk of the benefits are with regards to canceling notifications and determining if notifications are enabled on API 19 and below. Specifically with regard to notify(), NotificationManagerCompat can leverage side channel notifications on older Android API levels. This allows you to register a NotificationCompatSideChannelService that you can use to provide more robust grouping functionality on these older Android APIs.

like image 147
jdonmoyer Avatar answered Sep 27 '22 20:09

jdonmoyer