Firebase Messaging
Step 6: FCM Integration
6.1 Steps for Host Apps with Existing FCM Implementation
Note: Follow these steps if your application has Firebase Cloud Messaging (FCM). If not, you can skip this section.
6.1.1 FCM Token Integration and Message Handling
If you want to use the FCM project of the SDK to handle the FCM integration (this will be deprecated in the future), use the following code in your FirebaseMessagingService class:
public void onNewToken(String s) {
super.onNewToken(s);
// Add code to refresh IU Token
IUApp.refreshFCMToken(this);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Send only messages targeted for the SDK to the SDK
if (remoteMessage.getFrom().equals(IUApp.getFCMSenderId())) {
// Delegate the handling of FCM messages to the SDK
IUApp.handleFCMMessage(this, remoteMessage);
return;
}
}
Alternatively, if the integration is using the FCM project (Sender ID) of the application, use this method:
public void onNewToken(String hostAppToken) {
super.onNewToken(s);
// Add code to save IU Token
IUApp.saveFCMToken(this, hostAppToken);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Delegate the handling of FCM messages to the SDK
IUApp.handleFCMMessage(this, remoteMessage);
}
To enable DR to handle FCM messages when the sender is DR, add the following code in your Firebase implementation class's onMessageReceived
method:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Enable IU to handle messages targeted for IU
if (remoteMessage.getFrom().equals(IUApp.getFCMSenderId())) {
IUApp.handleFCMMessage(this, remoteMessage);
return;
}
// Continue code for host apps.
}
6.2 Steps for Host Apps without Current FCM Integration
Note: If your project already has a
google-services.json
file, skip this step. Otherwise, follow one of the options below.
Option 1: Set up Google Play Services Project
- Create a Firebase project and app in the Google Firebase console that represents your app.
- Add the corresponding
google-services.json
file to your project directory. - Follow these steps:
- Add a project.
- Add an app to the project.
- Download
google-services.json
. - Add it to the project folder.
6.3 Configure IU Server for the Host App
Minimal configuration needs to be done on the DR Server to connect to the host app via FCM. Provide the package name of the host app to DR.
Updated almost 2 years ago