The appearance of push notifications sent to Android devices in DeltaDNA campaigns can be customized. This tutorial will cover all of the requirements and steps needed to change the apperance of your notifications while using either the Unity SDK or the Android SDK.

Pre-requisites

  • Your game has either the Unity SDK (at least v5.0.7) or Android SDK integrated
  • Your game is set up to receive Android Push Notifications from DeltaDNA
    • For games using the Unity SDK, the Android Push Notification Tutorial will guide you through the steps to set that up
    • For games using the Android SDK, please ensure you are using the deltadna-sdk-notifications addon
  • The API target level for your game should be above 21

Acquiring the SDK notification addon for Unity

If you are using the Unity SDK, you will need to import the deltadna-sdk-notifications addon into your project.

  1. Download the android-sdk zip file from Github.
  2. Open the android project in Android Studio.
  3. You can now customize the notifications by extending the NotificationListenerService class and NotificationFactory class found under library-notifications in the project.
  4. Build the SDK by running gradlew clean build check from the root directory of the project.
  5. To bring your customized notifications into your Unity project, copy the deltadna-sdk-notifications-x.xx.x.-release.aar file from library-notifications/build/outputs/aar in the android project to Assets/Plugins/Android/libs in your Unity project (if the libs folder does not yet exist in your Unity project, please make sure to create it)
  6. In Unity, edit the baseProjectTemplate.gradle and remove the maven section under repositories .
  7. Edit the mainTemplate.gradle file and remove the deltadna-sdk-notifications dependency. Add api "com.google.firebase:firebase-messaging:20.2.0" to dependencies .

Customizing the notification

Setting the small icon

The small icon is the icon which appears in the status bar when a user gets a notification. These icons must be white with a transparent background. The icon should be saved in the Android project under the res/drawable folder. For a game using the Unity SDK, the small icon can be set by adding the name of the drawable resource in the configuration panel under Notification Icon.

For a game using the Android SDK, add the following snippet of code under the Firebase meta-data tags in the Android Manifest:

Customizing the main notification appearance

To customise the notification, the notification listener service and the notification builder will need to be extended. The following code snippets will create the basic notifications which are normally sent by the SDK. You can edit the builder code to suit your customization needs.

StyledNotificationListenerService.java:

StyledNotificationFactory.java:

Google’s push notification documentation describes the majority of customizations options which you might wish to use for your notifications. Once you have customized the notifications to suit you needs, you will need to update the listener service for Android notifications. For a game using the Unity SDK, this can be updated in the DeltaDNA configuration panel in the field above the Notification Icon field. For a game using the Android SDK, edit the Android Manifest such that the listener service is now looking at the new notifications.