Skip to content

Live Updates for Android

Learn how to use Android Live Updates in the Braze SDK, also known as Progress Centric Notifications. These notifications are similar to Live Activities for the Swift Braze SDK, allowing you to display interactive lock-screen notifications. Android 16 introduces progress-centric notifications to help users seamlessly track user-initiated, start-to-end journeys.

How it works

You can use the IBrazeNotificationFactory interface to customize how Braze push notifications are displayed. By extending BrazeNotificationFactory, Braze will call your factory’s createNotification() method before the notification is displayed to the user. It will then pass a payload containing custom key-value pairs sent through the Braze dashboard or REST API.

Displaying a Live Update

In this section, you’ll partner with Superb Owl, the host of a new game show where wildlife rescue teams compete to see who can save the most owls. They’re looking to leverage Live Updates in their Android app, so they can display the status of an on-going match and make dynamic updates to the notification in realtime.

An example Live Update from Android

Prerequisites

Before you can use this feature, you’ll need to integrate the Android Braze SDK.

Step 1: Create a custom notification factory

In your application, create a new file named MyCustomNotificationFactory.kt that extends BrazeNotificationFactory to handle how Braze Live Updates are displayed.

In the following example, Superb Owl created a custom notification factory to display a Live Update for on-going matches. In the next step, you’ll create a new method called getTeamInfo to map a team’s data to the activity.

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
32
33
34
35
class MyCustomNotificationFactory : IBrazeNotificationFactory {
    override fun createNotification(payload: BrazeNotificationPayload): Notification? {
        val notificationBuilder = populateNotificationBuilder(payload)
        val context = payload.context ?: return null

        if (notificationBuilder == null) {
            brazelog { "Notification could not be built. Returning null as created notification." }
            return null
        }
        notificationBuilder.setContentTitle("Android Live Updates").setContentText("Ongoing updates below")
        setProgressStyle(notificationBuilder, context)
        return notificationBuilder.build()
    }

    private fun setProgressStyle(notificationBuilder: NotificationCompat.Builder, context: Context) {
        val style = NotificationCompat.ProgressStyle()
            .setStyledByProgress(false)
            .setProgress(200)
            .setProgressTrackerIcon(IconCompat.createWithResource(context, R.drawable.notification_small_icon))
            .setProgressSegments(
                mutableListOf(
                    NotificationCompat.ProgressStyle.Segment(1000).setColor(Color.GRAY),
                    NotificationCompat.ProgressStyle.Segment(200).setColor(Color.BLUE),
                )
            )
            .setProgressPoints(
                mutableListOf(
                    NotificationCompat.ProgressStyle.Point(60).setColor(Color.RED),
                    NotificationCompat.ProgressStyle.Point(560).setColor(Color.GREEN)
                )
            )

        notificationBuilder.setStyle(style)
    }
}

Step 2: Map custom data

In MyCustomNotificationFactory.kt, create a new method for handling data when Live Updates are displayed.

Superb Owl created the following method to map each team’s name and logo to expanded Live Updates:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class CustomNotificationFactory : BrazeNotificationFactory() {
    override fun createNotification(payload: BrazeNotificationPayload): Notification? {
        // Your existing code
        return super.createNotification(payload)
    }

    // Your new method
    private fun getTeamInfo(team: String?): Pair<String, Int> {
        return when (team) {
            "WBF" -> Pair("Wild Bird Fund", R.drawable.team_wbf)
            "OWL" -> Pair("Owl Rehab", R.drawable.team_owl)
            else  -> Pair("Unknown", R.drawable.notification_small_icon)
        }
    }
}

Step 3: Set the custom notification factory

In your application class, use customBrazeNotificationFactoryto set your custom notification factory.

1
2
3
4
5
6
7
8
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Tell Braze to use your custom factory for notifications
        Braze.customBrazeNotificationFactory = MyCustomNotificationFactory()
    }
}

Step 4: Send the activity

You can use the /messages/send REST API endpoint to send a push notification to a user’s Android device.

Example curl command

Superb Owl sent their request using the following curl command:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
curl -X POST "https://BRAZE_REST_ENDPOINT/messages/send" \
  -H "Authorization: Bearer {REST_API_KEY}" \
  -H "Content-Type: application/json" \
  --data '{
    "external_user_ids": ["USER_ID"],
    "messages": {
      "android_push": {
        "title": "WBF vs OWL",
        "alert": "2 to 4 1:33 Q4",
        "extra": {
          "live_update": "true",
          "team1": "WBF",
          "team2": "OWL",
          "score1": "2",
          "score2": "4",
          "time": "1:33",
          "quarter": "Q4"
        },
        "notification_id": "ASSIGNED_NOTIFICATION_ID"
      }
    }
  }'

Request parameters

Step 5: Update the activity

To update the existing Live Update with new data, modify the relevant key-value pairs assigned to messages.extra, then use the same notification_id and call the /messages/send endpoint again.

HOW HELPFUL WAS THIS PAGE?
New Stuff!
OSZAR »