Customize Push Notifications for Android
The NotificationCustomizationOptions class of the Salesforce Engagement SDK 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 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).
Here’s how you can configure and set icons:
- Small icons: Provide the resource ID within
NotificationCustomizationOptionswhen usingMarketingCloudConfigBuilder. Alternatively, you can specify the icon’s resource name directly in the Engagement UI. - Large icons: Provide the resource name and optional public URL for remote retrieval in the Engagement UI.
- Rich button icons: Provide the resource names in the Engagement UI.
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 on the Engagement UI. If its 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 sample code creates a notification channel namedmyaudio, enables badges and lights, and sets a default importance level. -
In the Marketing Cloud Engagement UI, set the sound file name and extension in the Custom section of Sound settings.
Custom sounds can use these file formats:
.mp3,.wav,.aac,.m4a
This sample code configures the SDK for an Android application. It sets up notification customization options, including the small icon, launch intent, and notification channel ID.