Messages
In-app messaging and push notifications with the Grovs Android SDK
If console messages have automatic display enabled in your dashboard, they will appear in your app without any additional integration.
Push notifications
Follow the steps below to enable push notifications for messages sent from the Grovs dashboard.
1. Add Firebase Cloud Messaging to your project
If your app doesn't already use Firebase:
- Go to the Firebase Console and add your Android app
- Download the
google-services.jsonfile and place it in your app'sapp/directory - Add the Firebase dependencies to your project:
// project-level build.gradle
plugins {
id("com.google.gms.google-services") version "4.4.2" apply false
}
// app-level build.gradle
plugins {
id("com.google.gms.google-services")
}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:33.7.0"))
implementation("com.google.firebase:firebase-messaging")
}2. Upload your Firebase credentials to Grovs
Grovs uses the Firebase Cloud Messaging v1 API, which requires a Service Account JSON key and your Firebase Project ID.
Generate a Service Account key
- In the Firebase Console, go to Project Settings → Service Accounts
- Click Generate new private key
- A
.jsonfile will be downloaded — keep it safe
Find your Firebase Project ID
- In the Firebase Console, go to Project Settings → General
- Copy the Project ID (e.g.
my-app-12345)
Upload to Grovs
- In the Grovs dashboard, go to your app's Android Setup → Push Notifications
- Upload the Service Account JSON key file
- Enter your Firebase Project ID
- Save your changes
3. Request notification permission
On Android 13 (API 33) and above, you must request the POST_NOTIFICATIONS permission at runtime. Add it to your AndroidManifest.xml:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />Then request it in your activity:
import android.Manifest
import android.os.Build
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 0)
}4. Pass the FCM token to Grovs
Retrieve the FCM token and forward it to the SDK:
FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
Grovs.pushToken = token
}You should also update the token when it refreshes. The SDK ships its own FirebaseMessagingService that displays Grovs messages, and Android delivers each push to only one such service. If you declare your own, it takes precedence, so it must hand Grovs pushes back to the SDK from onMessageReceived:
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import io.grovs.Grovs
import io.grovs.handlers.handleGrovsNotification
class MyMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
Grovs.pushToken = token
}
override fun onMessageReceived(message: RemoteMessage) {
if (handleGrovsNotification(message)) return // a Grovs message, shown by the SDK
// Handle your own pushes here
}
}handleGrovsNotification returns false for pushes that did not come from Grovs, so your own handling is unaffected. Register the service in your AndroidManifest.xml:
<service
android:name=".MyMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>To use your own small icon for Grovs notifications, add a meta-data entry naming a drawable:
<meta-data android:name="io.grovs.NotificationIconSmall" android:value="ic_notification" />Push notifications require a physical device or an emulator with Google Play Services.
Displaying messages
Show the full list of messages as a modal fragment:
Grovs.displayMessagesFragment {
// Fragment was dismissed
}Nothing is shown while the SDK is disabled or not yet configured — see Privacy & Consent.
Automatically displayed messages
Messages flagged for automatic display open on their own. To know when the user closes one — to resume a flow you paused, for example — register a listener. isLast is true when no other automatically displayed message is still on screen:
Grovs.setOnAutomaticNotificationsListener { isLast ->
if (isLast) resumeOnboarding()
}Unread count
Get the number of unread messages — useful for showing a badge:
// Using coroutines
lifecycleScope.launch {
val count = Grovs.numberOfUnreadMessages()
Log.d("Grovs", "Unread: $count")
}
// Using a callback
Grovs.numberOfUnreadMessages(lifecycleOwner = this) { count ->
Log.d("Grovs", "Unread: $count")
}Both forms return null when the SDK is not configured, not authenticated, or disabled.