react-native-intercom: Doesn't receive Push Notifications on Android

Hello, First off, thanks for a great library!

98% of the implementation went swiftly and easily but getting pushes to show up has shown itself to be impossible (for me at least).

Problem

To repeat, the problem is that I can’t get push notifications sent from Intercom to show up on an Android device. In App messages work fine and all the other features. The user used for testing is verified to be accepting pushes and we’re sending the push tokens to Intercom like this:

FCM.getFCMToken().then(pushToken => {
  if (pushToken) {
    // Send to internal backend push service
    this.props.postUserPush(pushToken, 'fcm')
    Intercom.sendTokenToIntercom(pushToken)
  }
})

And when running adb logcat I’m seeing MessagingService: Remote message received when sending pushes from Intercom. Which I interpret as the push arriving at the device but something blocks it from showing up, ergo some problem with my implementation. But I can’t for the life of me figure out what’s wrong.

Environment

We have an existing Push Notification setup using react-native-fcm which is verified to be receiving pushes from our own Push Service as before.

Some code

build.gradle

...
compileSdkVersion 26
buildToolsVersion "26.0.2"
...
minSdkVersion 16
targetSdkVersion 23
...
...
compile project(':react-native-fcm')
compile 'com.google.firebase:firebase-core:11.+'
...
compile 'io.intercom.android:intercom-sdk-base:4.+'
compile 'io.intercom.android:intercom-sdk-fcm:4.+'
compile 'com.google.firebase:firebase-messaging:11.+'

AndroidManifest.xml

...
<service android:name="com.robinpowered.react.Intercom.IntercomIntentService" android:exported="false">
    <intent-filter android:priority="999">
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
<receiver android:name="io.intercom.android.sdk.push.IntercomPushBroadcastReceiver" tools:replace="android:exported" android:exported="true" />
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

<service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>
...

Any help or guidance would be greatly appreciated!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 33 (1 by maintainers)

Most upvoted comments

I fixed this issue by overriding the MessagingService of the react-native-fcm library. This gives the effect of IntercomIntentService not being used since the push handling happens in the class OverriddenMessagingService (just an example name).

Example:

public class OverriddenMessagingService extends MessagingService {
    private static final String TAG = "OverriddenMessagingService";
    private final IntercomPushClient intercomPushClient = new IntercomPushClient();

    @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);
        }
    }
}

@vvusts - ha, nope - I realised that a couple hours after I implemented this…

I moved the creation of the channels to native land and now I can. So in my MainApplication.java I now have:

    @Override
    public void onCreate() {
        // ...
        SoLoader.init(this, /* native exopackage */ false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel intercomChannel = new NotificationChannel("intercom_chat_replies_channel", "Intercom Replies", importance);
            intercomChannel.setDescription("Replies from Support (Chat to us)");
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            assert notificationManager != null;
            notificationManager.createNotificationChannel(intercomChannel);
        }
    }

@jrbaudin I implemented the following and still could not get it working. Could you be more specific? Do I need to do any JS for this to work? Will using any of the libraries JS functions override what’s done here? Which server key did you use: legacy or standard? Did you specify a sender id? My FCM notifications are working from firebase, just not from Intercom. I’m using react-native-firebase, would make a difference in my overrides? They seem to have the same classes.

package com.my.app;

import io.invertase.firebase.messaging.*;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import io.intercom.android.sdk.push.IntercomPushClient;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class MainInstanceIdService extends InstanceIdService {
  private final IntercomPushClient intercomPushClient = new IntercomPushClient();
  private static final String TAG = "InstanceIdService";

  /**
   * Called if InstanceID token is updated. This may occur if the security of
   * the previous token had been compromised. This call is initiated by the
   * InstanceID provider.
   */
  @Override
  public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    intercomPushClient.sendTokenToIntercom(getApplication(), refreshedToken);
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // Broadcast refreshed token
    Intent i = new Intent("io.invertase.firebase.messaging.FCMRefreshToken");
    Bundle bundle = new Bundle();
    bundle.putString("token", refreshedToken);
    i.putExtras(bundle);
    sendBroadcast(i);
  }
}
///
package com.my.app;
import io.invertase.firebase.messaging.*;
import android.content.Intent;
import android.content.Context;
import io.intercom.android.sdk.push.IntercomPushClient;
import com.google.firebase.messaging.RemoteMessage;
import android.util.Log;
import java.util.Map;

public class MainMessagingService extends MessagingService {
    private static final String TAG = "MainMessagingService";
    private final IntercomPushClient intercomPushClient = new IntercomPushClient();

    @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);
        }
    }
}

@vongohren had same problem on nativescript.

implementation 'io.intercom.android:intercom-sdk-base:6.+'

does not create notification channel for push notifications

implementation 'io.intercom.android:intercom-sdk:6.+'

solved the problem. Didn’t spot that sdk-base and sdk difference at first…

I would like to add one update to this.

Solution from @mtford90 works well. But later I found that Intercom Android SDK implements this on their own, since version 4.0.0 here changelog:

What fixed the same issue for me was using this sdk in my build.gradle

implementation 'io.intercom.android:intercom-sdk:5.+'

I removed the io.intercom.android:intercom-sdk-fcm:5.+ which was recommended in readme here.

After this it all worked out of the box.

@vvusts

import android.app.NotificationChannel;
import android.app.NotificationManager;

This + the solution in #208 helped me out. I’m using react-native-firebase and react-native-intercom with FCM. I had to add this MessagingService code, but also had to remove the <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service> code in the manifest in favour of the manifest code specified in these issues.