DEV Community

Aziz
Aziz

Posted on

Android Push Notifications implementation made easy with Bloomreach

Push notification

Introduction

Push notifications help your app engage users effectively. This guide explains how to implement push notifications on Android using Bloomreach(formerly Exponea) from scratch to a working feature.

Prerequisites

  • Android app using Kotlin
  • Firebase Cloud Messaging (FCM) configured
  • Bloomreach account with push enabled
  • Basic understanding of Android app lifecycle

High Level Architecture

  • App registers with FCM and obtains a device token
  • Token is sent to Bloomreach SDK
  • Bloomreach sends push campaigns via FCM
  • FCM delivers message to device
  • App displays notification

Firebase Setup

  • Add Firebase to your project via Firebase Console.
  • Place google-services.json in your app/ folder.
  • Add dependencies in build.gradle:
implementation platform('com.google.firebase:firebase-bom:33.0.0')
implementation 'com.google.firebase:firebase-messaging-ktx'
Enter fullscreen mode Exit fullscreen mode

Apply Google services plugin:

plugins {
  id 'com.google.gms.google-services'
}
Enter fullscreen mode Exit fullscreen mode

Integrating the Bloomreach SDK(formerly Exponea)

Step 1: Add Exponea SDK

implementation("com.exponea.sdk:sdk:4.8.1")
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize SDK

  • Obtain projectToken, authorization, and baseURL from Bloomreach Engagement portal under Project Settings > Access Management > API
  • Ensure tracking consent is obtained before initialization
val configuration = ExponeaConfiguration()
configuration.authorization = "Token YOUR_API_KEY"
configuration.projectToken = "YOUR_PROJECT_TOKEN"
configuration.baseURL = "https://api.exponea.com"
Exponea.init(this, configuration)
Enter fullscreen mode Exit fullscreen mode

Step 3: Place SDK Initialization

  • In your Application subclass onCreate() method:
class MyApplication : Application() {
  override fun onCreate() {
  super.onCreate()

  val configuration = ExponeaConfiguration()
  configuration.authorization = "Token YOUR_API_KEY"
  configuration.projectToken = "YOUR_PROJECT_TOKEN"
  configuration.baseURL = "https://api.exponea.com"

  Exponea.init(this, configuration)
  }
}
Enter fullscreen mode Exit fullscreen mode

Register your custom application class in AndroidManifest.xml:

<application android:name=".MyApplication">...</application>
Enter fullscreen mode Exit fullscreen mode

Push Notifications Setup

Enable Push Notifications

  • Bloomreach Engagement sends notifications via scenarios.
  • Notifications can be standard alerts or silent for background tasks. Implement Firebase Messaging Service
import android.app.NotificationManager
import android.content.Context
import com.exponea.sdk.Exponea
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage

class MyFirebaseMessagingService: FirebaseMessagingService() {
  private val notificationManager by lazy {
    getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
  }

  override fun onMessageReceived(message: RemoteMessage) {
    super.onMessageReceived(message)
    if (!Exponea.handleRemoteMessage(applicationContext, message.data, notificationManager)) {
    // message from another provider
    }
  }

  override fun onNewToken(token: String) {
    super.onNewToken(token)
    Exponea.handleNewToken(applicationContext, token)
  }
}
Enter fullscreen mode Exit fullscreen mode

Register service in AndroidManifest.xml:

<service android:name="MyFirebaseMessagingService" android:exported="false">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>
Enter fullscreen mode Exit fullscreen mode

Configure FCM in Bloomreach

  • Create a service account in Google Cloud and generate a private key
  • In Bloomreach Engagement, add Firebase Cloud Messaging integration using the JSON key

Dashboard

  • Select the integration in Project Settings > Channels > Push Notifications > Firebase Cloud Messaging Integration

Integration

After setup, your app can receive push notifications via Bloomreach and track tokens automatically

Push part

Top comments (0)