intercom icon indicating copy to clipboard operation
intercom copied to clipboard

Push notifications not working for Android

Open lippytak opened this issue 2 years ago • 18 comments

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

  • I confirmed the device/app can receive push notifications via a manual Firebase Cloud Messaging notification to the registration token
  • Push works on iOS as expected
  • Confirmed the app has notification permissions enabled
  • Tested on multiple devices with the app installed both via Android Studio and via Internal app sharing on the Play Store

Platforms:

  • OS: Android, various devices/versions

Any help greatly appreciated!

lippytak avatar May 25 '23 03:05 lippytak

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

joaodacolsoares avatar Jun 30 '23 10:06 joaodacolsoares

Me too, still there is no solution?

JanahiX avatar Aug 23 '23 07:08 JanahiX

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 android:name="com.capacitorjs.plugins.pushnotifications.MessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

Maybe that will help fining a proper solution

JanahiX avatar Aug 31 '23 10:08 JanahiX

Did anyone solve this issue?

nichovski avatar Nov 09 '23 09:11 nichovski

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
  • At the top of the file
apply plugin: 'com.google.gms.google-services'
  • Inside dependencies
implementation 'io.intercom.android:intercom-sdk:10.6.1'
implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"

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

Emieldv avatar Jan 25 '24 09:01 Emieldv

This probably also fixes #84

Emieldv avatar Jan 25 '24 09:01 Emieldv

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?

RobSchilderr avatar Mar 25 '24 11:03 RobSchilderr

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()?

fmp777 avatar Jun 11 '24 18:06 fmp777

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

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

stewones avatar Jun 11 '24 19:06 stewones

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 avatar Sep 04 '24 06:09 jpike88