Having trouble with Intercom push notifications. I am unable to receive any push notifications on the device from Intercom; standard notifications sent from FCM work perfectly as expected.
Have followed this tutorial, and have added the server key to Intercom as suggested.
CloudMessaging.java
public class CloudMessaging extends FirebaseMessagingService {
private final IntercomPushClient intercomPushClient = new IntercomPushClient();
public void getFirebaseInstanceID() {
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
intercomPushClient.sendTokenToIntercom(application, token);
);
}
}
});
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map message = remoteMessage.getData();
if (intercomPushClient.isIntercomPush(message)) {
Log.d(TAG, "Intercom message received");
intercomPushClient.handlePush(getApplication(), message);
} else {
super.onMessageReceived(remoteMessage);
}
}
manifest file
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".CloudMessaging"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
You only need one instance of "com.google.firebase.MESSAGING_EVENT"
in the Gradle file. In my case I stuck with .CloudMessaging
as that is where the Intercom notification is handled as shown above. My CloudMessaging
class needed to a have a public constructor with 0 input fields to open when the notification is recieved. eg.
Gradle File
<service
android:name=".CloudMessaging"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
CloudMessaging Class
public CloudMessaging() {
//dont delete or you wont get push notifications buddy
}
CloudMessaging(Context context, Application application) {
this.context = context;
this.application = application;
sharedPref = context.getSharedPreferences(FCM_ID_SHAREDPREF, MODE_PRIVATE);
}
The next most important thing is ensure you are using the correct Intercom SDK. I had originally implemented a 'base' sdk that did not have push notification capability. Make sure you have the full sdk.
Bad SDK
dependencies {
implementation 'io.intercom.android:intercom-sdk-base:x.x.+'
}
Good SDK
dependencies {
implementation 'io.intercom.android:intercom-sdk:x.x.+'
implementation 'com.google.firebase:firebase-messaging:x.+'
}