Push Notifications Setup for Firebase
Before you begin, make sure youāve completed these steps:
Expected result of the āPush Notifications Setup for Firebaseā step:You can send aĀ mobile push notification from Maestra and itĀ isĀ displayed onĀ the target device.
ToĀ check that your push notifications are sent correctly, please refer toĀ this guide.
1. Integrate your app with Firebase
Follow these steps from Googleās guidelines onĀ how toĀ Add Firebase toĀ Your Android Project:
- register your app with Firebase;
- download and add the
google-services.jsonconfiguration asĀ instructed; - enable Google Play services inĀ your app;
- add
firebase-messagingtoĀbuild.gradle; - send 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 (more details here, implementation example here).
In AndroidManifest.xml:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>In MainActivity.kt file:
private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
if (isGranted) {
Mindbox.updateNotificationPermissionStatus(this)
}
}
if (ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.POST_NOTIFICATIONS
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}2. Set up Notification Display
Suitable if NO custom logic is required.
Suitable when custom logic IS required.
Use
[setMessageHandling](https://developers.maestra.io/docs/android-sdk-methods)to define how the SDK should behave when image downloads fail, or to implement custom handling logic.
3. Register aĀ push notification processing service toĀ AndroidManifest.xml
Add the following code toĀ AndroidManifest.xml:
<application ...>
...
<service android:name=".MindboxFirebaseMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
...
</application>4. Update your init method toĀ always display push notifications
4.1 Add aĀ library toĀ process push notifications
Add aĀ library toĀ process push notifications to the dependencies block in app/build.gradle (Module: app).
Itās recommended to use a fixed version to keep updates under control. For the latest release, refer toĀ the Maven Central Repository Search.
dependencies {
...
implementation 'cloud.mindbox:mobile-sdk:{version}'
implementation 'cloud.mindbox:mindbox-firebase'
...
}4.2 Specify the library inĀ the init method
In the Mindbox.init method, which should be called from your appās onCreate callback, specify that this build uses MindboxFirebase.
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.MindboxConfiguration
import cloud.mindbox.mindbox_firebase.MindboxFirebase
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// ....
// Before
// Mindbox.init(applicationContext, configuration, listOf())
// You need
Mindbox.init(applicationContext, configuration, listOf(MindboxFirebase))
// ...
}
}Add a call to Mindbox.initPushServices in your appās onCreate callback.
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mindbox_firebase.MindboxFirebase
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// ....
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase))
Mindbox.init(applicationContext, configuration, listOf(MindboxFirebase))
// ...
}
}
Verify the result of the āPush Notifications Setup for 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 15 days ago

