Android - Push Receiver Module Interface
PushReceiverModule interface helps you connect into the Firebase push notification
system. Useful if your module needs to send or receive notifications.
Q2 routes all incoming FCM messages through each registered PushReceiverModule, letting your
module claim the ones that belong to it. For a full explanation of how Firebase Cloud Messaging
works, how Q2's push infrastructure is structured, and how to test locally, see
Notifications.
DevApp Setup
If your module requires push notification support, add the following dependencies to your DevApp build.gradle:
implementation "com.q2.push:push:$q2Version"
implementation "com.app.q2.modules.push.q2_push_service:q2_push_service:$q2Version"
These modules are not included in core by default and must be explicitly declared when push notification functionality is needed. Without them, the app will crash on startup when push is enabled in your configuration.
Implementation
Create a class, and have it inherit the PushReceiverModule. Once inherited, override the
functions provided and add your logic as required.
class PushReceiver(private val sdkUtils: SdkUtils): PushReceiverModule {
/**
* On enroll, gives you access to the [NotificationManager], which allows you to create your own
* channels.
*/
override fun createNotificationChannel(context: Context, notificationManager: NotificationManager) {
}
/**
* When Firebase issues a new token, it will be sent to your module here, allowing you to keep up to date
*/
override fun onNewToken(token: String) {
}
/**
* When Firebase sends a notification to the device, Core will send it to each module to verify if the notification
* is theirs. If the remote message is yours then consume it and return true. Otherwise return false and do
* not consume it
*/
override fun willConsumeNotification(
context: Context,
remoteMessage: com.google.firebase.messaging.RemoteMessage
): Boolean {
// Return true if the notification is yours and you are going to consume it
return remoteMessage.data.containsKey(myKey)
}
}
Triggering From Core
PushReceiverModule is triggered automatically and does not require any work done on
Tecton. Once the device is enrolled into the Firebase system, you will start receiving
notifications and updated tokens when required.
SDKPushUtils
SdkUtils provides the SDKPushUtils which can be used to access the current registration token as well as other information associated to push notifications. See SDKUtils SDKPushUtils for more information.
Update Your settings.json
Ensure your settings.json file in the root of the DevApp is updated to reflect your
module changes. Learn more in Configuring settings.json.
Version History
DevApp Dependencies
The required build.gradle dependencies for push support have changed across SDK versions:
| SDK Version | Required Dependencies |
|---|---|
| 25.11.0 and older | No additional dependencies required |
| 26.1.0 – 26.2.0 | implementation "ngam-android.modules:push:$q2Version"implementation "ngam-android.modules:q2_push_service:$q2Version" |
| 26.3.0 and newer | implementation "com.q2.push:push:$q2Version"implementation "com.app.q2.modules.push.q2_push_service:q2_push_service:$q2Version" |
Note: The 26.1.0–26.2.0 artifact IDs are no longer published as of 26.3.0. Using them on 26.3.0 or newer will cause a build failure.