capacitor-community / intercom

Enable Intercom for Capacitor apps
https://capacitorjs.com/docs
MIT License
60 stars 77 forks source link

Push notifications not working for Android #87

Open lippytak opened 1 year ago

lippytak commented 1 year ago

Describe the bug I'm unable to get push notifications working on Android. I'm guessing this is a config/setup issue, but since this issue has come up a few times I was hoping to get it working and then contribute better instructions to this repo.

To Reproduce

  1. Install and configure @capacitor/push-notifications
  2. Enable Cloud Messaging API in Firebase (legacy) and add the Server key to Intercom (Settings > Install > Android > Push)
  3. Install and configure this plugin
  4. Add app code:
    import { Intercom } from '@capacitor-community/intercom';
    import { PushNotifications } from '@capacitor/push-notifications';
    PushNotifications.requestPermissions();
    PushNotifications.register();
    Intercom.registerUnidentifiedUser();
    Intercom.displayLauncher();
  5. Launch app > send Intercom message > close the app > reply to the message from the Intercom Inbox

Expected: Receive a push notification on the device after ~10 seconds.

Result: Nothing. The message comes through as expected if you resume the app.

Additional context

Platforms:

Any help greatly appreciated!

joaodacolsoares commented 1 year ago

I have the same issue here, it works on iOS but doesn't work in Android.

JanahiX commented 1 year ago

Me too, still there is no solution?

JanahiX commented 1 year ago

I have noticed that if we comment out the below service from "@capacitor/push-notifications/android/src/main/AndroidManifest.xml" it fix Intercom push issue but normal notification from FCM will not work

`

    </service>

`

Maybe that will help fining a proper solution

nichovski commented 1 year ago

Did anyone solve this issue?

Emieldv commented 10 months ago

Hi Guys, I was experiencing this issue as well and managed to get it working in my app!

When looking trough the intercom push notifications documentation I noticed this step mentioning some extra configration that is needed when using intercom with other FCM setups.

As far as I understand it the @capacitor/push-notifications plugin and the capacitor-community/intercom plugin both try to handle incoming notifications and are thus overwriting each other or something like that.

I solved this by adding some custom native code to my android package which catches the push notification and hands it over to the correct plugin:

  1. Add a file called CustomMessagingPlugin.java to android/app/src/main/java/<com>/<appname>/<app> (This should be the same place where the MainActivity.java file is located)


  1. Add the following code to this file:
package <YOUR_PACKAGE_NAME (com.appname.app)>;

import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;

import io.intercom.android.sdk.push.IntercomPushClient;

public class CustomMessagingPlugin extends FirebaseMessagingService {

    private final IntercomPushClient intercomPushClient = new IntercomPushClient();

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map message = remoteMessage.getData();

        if (intercomPushClient.isIntercomPush(message)) {
            intercomPushClient.handlePush(getApplication(), message);
        } else {
            super.onMessageReceived(remoteMessage);
        }
    }
}


  1. Add the following code to your AndroidManifest.xml (As a child of <application>)
<service android:name=".CustomMessagingPlugin" android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>


  1. Add the following to android/app/build.gradle


This probalbly isn't the best way to fix this but at least it works 🤷‍♂️

Emieldv commented 10 months ago

This probably also fixes #84

RobSchilderr commented 8 months ago

I am not able to get them working on iOS neither. Getting the error: Intercom.sendPushTokenToIntercom()" is not implemented on ios. Could anyone share the code to get iOS working?

fmp777 commented 5 months ago

Our app has both OneSignal and Intercom. OneSignal works fine, Intercom pushes do not (ios nor android). The patch above by Emieldv caused our app to crash as soon as you launched intercom interface. We did consider the versions in his patch to be outdated and updated accordingly, but to no avail. Intercom push configuration is setup exactly the same as our OneSignal. We have an older cordova app using the same configs, but leveraging the cordova-plugin-intercom and calling intercom.registerPush(), and that works fine. Is there a reason this package uses @capacitor/push-notifications vs Intercom.registerPush()?

stewones commented 5 months ago

Is there a reason this package uses @capacitor/push-notifications vs Intercom.registerPush()?

not that I recall. That would be a reasonable change.

jpike88 commented 2 months ago

we use onesignal too, so this plugin is unusable for us until then. maybe code from https://github.com/intercom/intercom-cordova can be looked at to speed things up on this plugin

jpike88 commented 2 weeks ago

Just FYI to everyone, I forked it here and it's working for me, it's a bit rough in implementation so I advise to be careful and totally reinstall it, as I branched it from a pending PR I already submitted to this repo. https://github.com/capacitor-community/intercom/pull/113

https://github.com/aquipa/capacitor-intercom/tree/notifications-working