Android setup¶
- Create a Firebase project, register your Android app in it and download
google-services.jsonintoandroid/app/. -
Apply the Google services Gradle plugin.
In
android/settings.gradle.kts:Kotlinplugins { // ... id("com.google.gms.google-services") version "4.4.4" apply false }In
android/app/build.gradle.kts:Kotlinplugins { // ... id("com.google.gms.google-services") }
Without Firebase set up, the SDK still runs, but never gets a token.
The SDK's manifest already declares INTERNET and POST_NOTIFICATIONS, so the app needs no permission entries of its own.
On Android 13+, the system permission prompt only appears for apps that target API 33 or higher. For apps that target lower, Android shows its own prompt when the app creates its first notification channel; askForPermission() then shows the Settings dialog instead.
Android notifications¶
The notification service sends Android data messages, which Android doesn't show by itself. The SDK's messaging service shows them, also while the app is in the background or not running. It needs no setup, unless the app uses firebase_messaging (see below).
- Duplicates: every notification has an id. The service may send a notification again when it didn't hear back from FCM, and a copy of one the device already received isn't shown again, even if the user dismissed the first.
- Turned off: nothing is shown while notifications, or the SDK's channel, are turned off for the app.
- In the foreground: shown, unless the configuration says
showNotificationsInForeground: false. - Pictures: a notification with a picture shows it when expanded. The picture is downloaded over https only, at most 5 MB and within 5 seconds; otherwise the notification is shown without it.
- Tapping opens the app's launch activity, with the notification's id in the
dk.zaur.plingbuddy.notification_idintent extra. A running app gets the intent inonNewIntent, and native activities on top of the launch activity are closed. The SDK reports the tap when an activity starts with it, and the plugin passes it on from the Flutter activity'sonNewIntent. - Only the service's messages are shown: those whose
datahas anotification_id. Messages from other senders, including ones with anotificationblock, are left to the app.
Channel, icon and colour¶
The SDK posts to one notification channel, plingbuddy_default, named "Notifications" (translated to Danish, Swedish, Norwegian, Finnish and German) with high importance: a heads-up banner with sound. It's created once the user allows notifications through askForPermission(), or else with the first notification. After that, only the user can change its importance, in the system settings.
To change the name, the small icon or the accent colour, define a resource with the same name in your app's android/app/src/main/res/:
<!-- values/strings.xml, plus values-da/strings.xml etc. for translations -->
<string name="plingbuddy_channel_name">News</string>
<!-- values/colors.xml; the default, transparent, means no accent colour -->
<color name="plingbuddy_color">#FF1E88E5</color>
The small icon is drawable/plingbuddy_ic_notification, a white bell by default. Replace it with a vector drawable of the same name in res/drawable/ (in Android Studio: New → Vector Asset). Android draws only the icon's shape, from its transparency, so it must be white on transparent; a full-colour launcher icon shows as a white square.
Using firebase_messaging too¶
Android delivers FCM messages to only one messaging service per app. The firebase_messaging plugin declares one too, with the same priority as the SDK's, so either may get them: if it's firebase_messaging's, the service's notifications are never shown.
firebase_messaging receives messages for its Dart handlers through a separate broadcast receiver, and uses its service only for onTokenRefresh. So declare one service in your app that does both: it extends firebase_messaging's service and passes messages to the SDK. In android/app/src/main/kotlin/<your package>/AppMessagingService.kt:
package <your package>
import com.google.firebase.messaging.RemoteMessage
import dk.zaur.plingbuddy.sdk.PlingBuddyMessaging
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService
class AppMessagingService : FlutterFirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
PlingBuddyMessaging.handleMessage(this, message)
}
}
Then declare it in android/app/src/main/AndroidManifest.xml and remove both plugins' services:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<!-- ... -->
<service android:name=".AppMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="dk.zaur.plingbuddy.sdk.PlingBuddyMessagingService"
tools:node="remove" />
<service
android:name="io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService"
tools:node="remove" />
</application>
</manifest>
This was checked against firebase_messaging 15.2.10. The service's messages also reach your onMessage and onBackgroundMessage handlers. If those show notifications themselves, skip messages whose data has a notification_id, or users get them twice.
Any other SDK with its own messaging service works the same way: call PlingBuddyMessaging.handleMessage(context, message) from the one service you keep. It blocks while a picture loads, so call it from onMessageReceived or another background thread. It returns false for a message that isn't the service's, or has no title or body, which the SDK left alone.