-
Notifications
You must be signed in to change notification settings - Fork 0
BD-7149 Update documentation for upcoming 18.0.0 release. #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0062832
fe1a45c
280c514
7e9cd8d
840a2cf
cfe15d3
cf9ca16
e9b1536
e23d6c9
68369d3
77fafaf
52e3ac6
2d5758a
fcd6c78
33883a8
ec95e6a
f217dc2
15bcde1
796f7e0
ea7705f
4062d04
327cde2
3e904e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| # Bluedot Push Notifications Module — Integration Guide | ||
|
|
||
| **SDK version:** 18.0.0 | ||
| **Module artifact:** `au.com.bluedot:pushnotifications` | ||
|
|
||
| ## Overview | ||
|
|
||
| Starting from version 18.0.0, push notification support is delivered as a **separate, optional module** — `pushnotifications`. | ||
|
|
||
| The module: | ||
| - Handles FCM token registration with the backend automatically. | ||
| - Displays notifications when a push message is received. | ||
| - Lets you customise the look of notifications. | ||
| - Provides callbacks for received and clicked notifications via a `PushNotificationsEventReceiver`. | ||
|
|
||
| ## Requirements | ||
|
|
||
| | Requirement | Value | | ||
| |---|---| | ||
| | Min SDK | 29 (Android 10) | | ||
| | Compile SDK | 36 | | ||
| | Firebase Cloud Messaging | `com.google.firebase:firebase-messaging:25.0.1` | | ||
| | Core Point SDK | `au.com.bluedot:pointsdk:18.0.0` | | ||
|
|
||
| > Using non-compatible versions of the Firebase dependencies may lead to runtime crashes or unexpected behaviour. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Configure Android Push Notifications credentials and campaign in Canvas. | ||
|
|
||
|  | ||
|
|
||
| Setup Push Notifications campaign in Canvas. | ||
|
|
||
|  | ||
|
|
||
| ## Step 1 — Add the dependency | ||
|
|
||
| Follow [Quick Start](https://docs.bluedot.io/Point%20SDK/Android/Quick%20Start#import-the-sdk) guide to set up the core SDK first, including the project configuration URL and initialisation. | ||
|
|
||
| In your **app-level** `build.gradle`, add the `pushnotifications` module alongside the core SDK: | ||
|
|
||
| ```groovy | ||
| dependencies { | ||
| // ... | ||
| implementation 'com.gitlab.bluedotio.android:point_sdk_push:18.0.0' | ||
| } | ||
| ``` | ||
|
|
||
| ## Step 2 — Firebase setup | ||
|
|
||
| The `pushnotifications` module uses **Firebase Cloud Messaging (FCM)** to receive push notifications. If your app doesn't use Firebase yet, follow the [official Android documentation](https://firebase.google.com/docs/cloud-messaging/android/get-started) to set it up. | ||
|
|
||
| > On Android 13 (API 33) and above, you must declare `POST_NOTIFICATIONS` permission in your manifest **and** request it at runtime. Follow official [Android documentation](https://developer.android.com/training/permissions/requesting) for details. | ||
|
|
||
| ## Step 3 — Implementation of FirebaseMessagingService | ||
|
|
||
| As part of Firebase Cloud Messaging integration you have implemented your own `FirebaseMessagingService` subclass. Now we are going to use it to bridge FCM events into the `pushnotifications` module. | ||
|
|
||
| ```kotlin | ||
| class MyFirebaseMessagingService : FirebaseMessagingService() { | ||
|
|
||
| override fun onNewToken(token: String) { | ||
| ServiceManager.getInstance(this).pushNotificationsManager.onNewFcmToken(token) | ||
| } | ||
|
|
||
| override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
| // use convenient extension functions from the pushnotifications module to check if the message is from Rezolve and convert it to RezolvePushData | ||
| if (remoteMessage.isRezolvePushNotification()) { | ||
| ServiceManager.getInstance(this).pushNotificationsManager.onMessageReceived(remoteMessage.toRezolvePushData()) | ||
| } else { | ||
| // Handle your own notifications here | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Register the service in `AndroidManifest.xml`: | ||
|
|
||
| ```xml | ||
| <service | ||
| android:name=".java.MyFirebaseMessagingService" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to show
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can define this service class with full package name (com.example.app.java.MyFirebaseMessagingService) or skip the package name and leave just enough information for the compiler to be able to identify the class in your code (as above). This example was taken straight from official Android docs: https://firebase.google.com/docs/cloud-messaging/android/receive-messages#edit-app-manifest |
||
| android:exported="false"> | ||
| <intent-filter> | ||
| <action android:name="com.google.firebase.MESSAGING_EVENT" /> | ||
| </intent-filter> | ||
| </service> | ||
| ``` | ||
|
|
||
| ## Step 4 — Listen for notification events | ||
|
|
||
| To receive callbacks when a notification is received or tapped by the user, create a `BroadcastReceiver` that extends `PushNotificationsEventReceiver`: | ||
|
|
||
| ```kotlin | ||
| class MyPushNotificationsEventReceiver : PushNotificationsEventReceiver() { | ||
| override fun onNotificationReceived(rezolvePushData: RezolvePushData, context: Context) { | ||
| // Called when a Rezolve push notification arrives | ||
| // Use rezolvePushData.campaignId, .zoneId, .notificationId, .data | ||
| } | ||
|
|
||
| override fun onNotificationClicked(rezolvePushData: RezolvePushData, context: Context) { | ||
| // Called when the user taps the notification | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Register the receiver in `AndroidManifest.xml`: | ||
|
|
||
| ```xml | ||
| <receiver | ||
| android:name=".MyPushNotificationsEventReceiver" | ||
| android:enabled="true" | ||
| android:exported="false"> | ||
| <intent-filter> | ||
| <action android:name="io.bluedot.point.PUSHNOTIFICATIONS" /> | ||
| </intent-filter> | ||
| </receiver> | ||
| ``` | ||
|
|
||
| ### NotificationData fields | ||
|
|
||
| | Field | Type | Description | Example value | | ||
| |---|---|---|------------------------------------------| | ||
| | `title` | `String` | Notification title (empty string if absent) | `"Title defined in Canvas Campaign"` | | ||
| | `body` | `String` | Notification body text (empty string if absent) | `"Body defined in Canvas Campaign"` | | ||
| | `pushVersion` | `String` | Push schema version | `"1.0"` | | ||
| | `campaignId` | `String` | Campaign UUID | `"b70e49c0-f12e-4ff1-b9f3-9d53767dc5b9"` | | ||
| | `zoneId` | `String` | Zone UUID | `"89060cba-a910-481a-aeb5-816182fdf01f"` | | ||
| | `notificationId` | `String` | Notification UUID | `"01J1ZQK8R4F9W6M0X9C1JZ7N2B"` | | ||
| | `data` | `Map<String, String>` | All remaining custom key-value pairs from the payload | `{"custom_key":"custom_value"}` | | ||
|
|
||
| --- | ||
|
|
||
| ## Step 5 — (Optional) Customise the notification appearance and behaviour | ||
|
|
||
| By default the module displays a standard notification using a built-in icon and the `IMPORTANCE_DEFAULT` channel. | ||
| On notification click the SDK sends the broadcast to the receiver defined in Step 4 and starts the default launcher activity defined for the app. | ||
|
|
||
| To override the appearance or behaviour, supply your own `NotificationCompat.Builder` **before** the first message arrives: | ||
|
|
||
| ```kotlin | ||
| val channel = NotificationChannel( | ||
| CUSTOM_PUSH_CHANNEL_ID, | ||
| "Custom Push Notifications", | ||
| NotificationManager.IMPORTANCE_HIGH | ||
| ) | ||
| val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
| notificationManager.createNotificationChannel(channel) | ||
|
|
||
| val contentIntent = PendingIntent.getActivity( | ||
| context, | ||
| 0, // request code — unique integer to distinguish this PendingIntent from others; | ||
| // use different values if you create multiple distinct PendingIntents | ||
| Intent(context, YourCustomActivity::class.java).apply { | ||
| flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP | ||
| // Optionally pass data: | ||
| putExtra("my_custom_id", "1234") | ||
| }, | ||
| PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE | ||
| ) | ||
|
|
||
| val customBuilder = NotificationCompat.Builder(context, CUSTOM_PUSH_CHANNEL_ID) | ||
| .setSmallIcon(R.drawable.your_notification_icon) | ||
| .setColor(ContextCompat.getColor(context, R.color.your_brand_color)) | ||
| .setPriority(NotificationCompat.PRIORITY_HIGH) | ||
| .setContentIntent(contentIntent) | ||
| .setAutoCancel(true) | ||
|
|
||
| ServiceManager.getInstance(context) | ||
| .pushNotificationsManager | ||
| .setCustomPushNotification(customBuilder) | ||
| ``` | ||
|
|
||
| > PendingIntent is a system-managed token that dies with the process. Make sure to set the custom builder early in the app lifecycle (e.g. in Application.onCreate) so it is available when the first notification arrives. If the module receives a message before you set the custom builder, it will create and use a default one. | ||
|
|
||
| > The module fills in `.setContentTitle()` and `.setContentText()` automatically from the message payload, so you do not need to set them in your builder. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.