Android | Push Notification Sending (Firebase)
Make sure these steps are completed successfully:
Expected result of the “Android | Push-notification setup | Firebase” step:A mobile push notification is sent from Maestra and is displayed on the device.
You can use this guide to verify that push notifications are being sent.
1. Integrate your app with Firebase.
From the official Firebase setup guide, you need to complete the following steps:
- Register your app in Firebase;
- Download the
google-services.jsonfile and add it to the project according to the instructions; - Enable Google Services in your app;
- Add
firebase-messagingtobuild.gradle; - Provide the Firebase Server Key to your Maestra Forward Deployed Marketer.
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.7.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
...
}If your app uses targetSdk 33, you also need to add a permission to receive notifications (learn more here, implementation example here).
In the AndroidManifest.xml file:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>№№2. Explicitly add the Mindbox SDK to build.gradle.
To use the Mindbox SDK, add the dependency to build.gradle file (app level).
dependencies {
implementation 'com.google.firebase:firebase-messaging:24.1.0'
}3. Implement notification rendering
Suitable if no custom logic is required.
Suitable if custom logic is required.
To define the behavior when image loading fails, or to implement custom logic, use the following method: setMessageHandling
4. Register the push notification handling service in AndroidManifest.xml.
Add the following entries to the AndroidManifest.xml file:
<application ...>
...
<service android:name=".MindboxFirebaseMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
...
</application>5. Update the initialization method to ensure push notifications are always displayed.
5.1 Add the library for handling push notifications in the app/build.gradle file to the dependencies block (Module: app).
It’s recommended to specify a fixed version to control updates. You can find the latest version here.
dependencies {
...
implementation 'cloud.mindbox:mindbox-firebase
...
}5.2. Specify the library in the Mindbox.initPushServices method
Mindbox.initPushServices methodIn the Application.onCreate method, call Mindbox.initPushServices with MindboxFirebase.
If this class does not exist in your project, create it:
- New → Kotlin Class
- Add the code from the example below.
- Register the class in
AndroidManifest.xml.
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mindbox_firebase.MindboxFirebase
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
// ....
// Required
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase))
// ...
}
}
Verify the result of the “Sending push notifications on Android via Firebase” step:A mobile push notification is sent from Maestra and is displayed on the device.
You can use this guide to verify that push notifications are being sent.
Updated 2 months ago

