Notifications
Notifications
Nuclei SDK by default will only process push notifications that are sent from Nuclei servers. Please find the below implementation reference for both FCM. The code should be written in FirebaseMessagingService.
- Setting up GCM or FCM with Nuclei SDK
@Override
public void onNewToken(String token) {
...
super.onNewToken(token);
if (SampleApplication.getNucleiSDK() != null) {
SampleApplication.getNucleiSDK().setPushNotificationKey(token);
} else {
// Save the token in device storage and give it to the nuclei SDK after initialization using setPushNotificationKey(token);
}
...
}
- Receiving FCM Notifications
When a notification is sent from Nuclei server, the same will be received by the partner's FirebaseMessagingService
. Nuclei SDK can check if the particular notification is from its own system and will be able to show the respective notification item in the device's status bar.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map data = remoteMessage.getData();
if (data != null && !data.isEmpty()) {
if (!SampleApplication.getNucleiSDK().handleNotification(data)) {
//Handle other push notification which is not for Nuclei
}
} else {
log("invalid notification data");
}
}