Skip to content

Android push notification integration

This reference article covers the Android push notification integration for the Unity platform.

These instructions are for integrating push with Firebase Cloud Messaging (FCM).

See our Unity ADM documentation for ADM integration instructions.

Step 1: Enable Firebase

To get started, follow the Firebase Unity setup documentation.

Step 2: Set your Firebase credentials

You need to input your Firebase Server Key and Sender ID into the Braze dashboard. To do this, log in to the Firebase Developers Console and select your Firebase project. Next, select Cloud Messaging under Settings and copy the Server Key and Sender ID:

In Braze, select your Android app on the App Settings page under Manage Settings. Next, enter your Firebase Server Key in the Firebase Cloud Messaging Server Key field and Firebase Sender ID in the Firebase Cloud Messaging Sender ID field.

Step 3: Implement automatic push integration

The Braze SDK can automatically handle push registration with the Firebase Cloud Messaging Servers to have devices receive push notifications.

The Unity editor shows the Braze configuration options. In this editor, the "Automate Unity Android Integration", "Push Notification Firebase Push", "Push Configuration Handle Push Deeplinks Automatically", "Push Configuration Push Notification HTML Rendering Enabled", and "Set Push Deleted/Opened/Received Listeners" are set. The fields "Firebase Sender ID", "Small/Large Icon Drawable", "Default Notification Accent Color" are also provided.

  • Automatic Firebase Cloud Messaging Registration Enabled
    Instructs the Braze SDK to automatically retrieve and send an FCM push token for a device.
  • Firebase Cloud Messaging Sender ID
    The Sender ID from your Firebase console.
  • Handle Push Deeplinks Automatically
    Whether the SDK should handle opening deep links or opening the app when push notifications are clicked.
  • Small Notification Icon Drawable
    The drawable should be displayed as the small icon whenever a push notification is received. The notification will use the application icon as the small icon if no icon is provided.

Step 4: Set push listeners

If you want to pass push notification payloads to Unity or take additional steps when a user receives a push notification, Braze provides the option of setting push notification listeners.

In Braze, select your Android app on the App Settings page under Manage Settings. Next, enter your Firebase Server Key in the Push Notification Settings field and Firebase Sender ID in the Push Notification Settings ID field.

Push received listener

The push received listener is fired when a user receives a push notification. To send the push payload to Unity, set the name of your game object and push the received listener callback method under the Set Push Received Listener.

Push opened listener

The push opened listener is fired when a user launches the app by clicking on a push notification. To send the push payload to Unity, set the name of your game object and push opened listener callback method under the Set Push Opened Listener.

Push deleted listener (Android only)

The push deleted listener is fired when a user swipes away or dismisses a push notification. To send the push payload to Unity, set the name of your game object and push deleted listener callback method under the Set Push Deleted Listener.

Push listener implementation example

The following example implements the BrazeCallback game object using a callback method name of PushNotificationReceivedCallback, PushNotificationOpenedCallback, and PushNotificationDeletedCallback respectively.

This implementation example graphic shows the Braze configuration options mentioned in the preceding sections and a C# code snippet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MainMenu : MonoBehaviour {
  void PushNotificationReceivedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationReceivedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification received: " + pushNotification);   
#elif UNITY_IOS
    ApplePushNotification pushNotification = new ApplePushNotification(message);
    Debug.Log("Push received Notification event: " + pushNotification);   
#endif  
  }

  void PushNotificationOpenedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationOpenedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification opened: " + pushNotification);  
#elif UNITY_IOS
    ApplePushNotification pushNotification = new ApplePushNotification(message);
    Debug.Log("Push opened Notification event: " + pushNotification);   
#endif  
  }

  void PushNotificationDeletedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationDeletedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification dismissed: " + pushNotification);  
#endif
  }
}

Implementation example

The sample project in the Braze Unity SDK repository contains a full working sample app that includes FCM.

Deep linking to in-app resources

Although Braze can handle standard deep links (such as website URLs, Android URIs, etc.) by default, creating custom deep links requires an additional Manifest setup.

For setup guidance, visit Deep Linking to In-App Resources.

Adding Braze push notification icons

To add push icons to your project, create an Android Archive (AAR) plug-in or Android library that contains the icon image files. For steps and information, refer to Unity’s documentation: Android Library Projects and Android Archive plug-ins.

HOW HELPFUL WAS THIS PAGE?
New Stuff!