Android Notifications Example with retro-compatibility (API 19+)
This example shows how to buid and show Notifications using android Notifications API.
The original Notification
API is compatible with API 26+ devices, but you can use NotificationCompat
classes using the android support libraries (com.android.support:support-v4
)
In this example, a NotificationHelper
class is created to help:
- Creating notification channels (Channel ID and Name) in compatibility mode (some properties are relevant only for newer API devices)
- There are 2 pre-generated channels:
DEFAULT_CHANNEL
andURGENT_CHANNEL
(in older devices, there is no difference)
- There are 2 pre-generated channels:
- Creating and showing notifications (Title, message and channel)
- Displaying the notification channel configuration using the channel ID.
Instance of NotificationHelper:
NotificationHelper notifications = new NotificationHelper(this);
Create a simple notification using a registered channel
notifications.notify(1001, "Title", "General Message", notifications.DEFAULT_CHANNEL);
notifications.notify(1002, "Title", "Urgent Message", notifications.URGENT_CHANNEL);
Calling the notification channel configurator
notifications.showNotificationSettings(this, notifications.URGENT_CHANNEL);