androidandroid-notificationsnotification-channel

What is the purpose of NotificationChannelCompat?


I saw this class before but cannot use it and I don't see many sample that use it. What exactly is the difference of NotificationChannelCompat from regular NotificationChannel?


Solution

  • NotificationChannels are only supported on SDK 26+. So the idea is that NotificationChannelCompat gracefully handles the situation where you call methods related to NotificationChannels on unsupported SDKs. Rather than crashing your app, it simply does nothing or returns an empty list on an unsupported SDK. So this avoids the situation where you need to handle notifications differently on SDK 26+ and SDK < 26. In practice, this isn't a big deal so nobody bothers with it.