Basic Push Notification Customization for Android
The NotificationCustomizationOptions class facilitates push notification customization through a NotificationChannelIdProvider, enabling the assignment of a specific Notification Channel for each NotificationMessage.
Additionally, NotificationLaunchIntentProvider defines the action to take when a user taps a NotificationMessage, alongside your application’s notification icon.
When you target apps that run Android 12 or later, specify the mutability of your Pending Intent. See Android Developer Documentation: Intents and Intent Filters.
The Mobile App Messaging SDK supports icons in various notification elements, including small icons in the status bar and notification header, large icons in the notification body, and rich button icons.
You can use icons by placing icon files in the PNG format inside drawables-**hdpi folders within your client app’s resources. The SDK then references these icons by their resource names (for example, ic_notification_icon).
For example, to use an icon named ic_notification_icon.png, place it in the appropriate drawables-**hdpi folder. Then, provide ic_notification_icon as the resource name. If it’s a small icon, you can also specify the resource ID in NotificationCustomizationOptions when using MarketingCloudConfigBuilder.
You can customize notification channels by setting priorities, colors, and sounds. To use a custom sound in notifications, follow these steps:
- Add the sound file to the app’s
res/raw/folder. - Create a notification channel for the audio file and configure it in the code using
NotificationChannelIdProvider. This code example creates a notification channel namedmyaudio, enables badges and lights, and sets a default importance level.
This sample code configures the Mobile App Messaging SDK for an Android application. It sets up notification customization options, including the small icon, launch intent, and notification channel ID.