Skip to content

Notifications

The 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 your app has its own messaging service (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. A hidden notification is reported to the service as suppressed.
  • 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.
  • Only the service's messages are shown: those whose data has a notification_id. Messages from other senders are left to the app.

Taps

Tapping opens the app's launch activity, with the notification's id in the dk.zaur.plingbuddy.notification_id intent extra. The SDK reports the tap when an activity is created with that intent.

A running app gets the tap in onNewIntent instead; pass it on there:

Kotlin
override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    PlingBuddy.handleIntent(this, intent)
}

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:

XML
<!-- 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 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.

Your own messaging service

Android delivers FCM messages to one messaging service per app. If your app has its own, remove the SDK's and pass messages on from yours:

Kotlin
class AppMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(message: RemoteMessage) {
        if (!PlingBuddyMessaging.handleMessage(this, message)) {
            // Not PlingBuddy's message: handle it yourself.
        }
    }
}
XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <application>
        <service
            android:name="dk.zaur.plingbuddy.sdk.PlingBuddyMessagingService"
            tools:node="remove" />
    </application>
</manifest>
  • handleMessage 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.