Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push notifications not working for Android #87

Open
lippytak opened this issue May 25, 2023 · 9 comments
Open

Push notifications not working for Android #87

lippytak opened this issue May 25, 2023 · 9 comments

Comments

@lippytak
Copy link

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!

@joaodacolsoares
Copy link

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

@JanahiX
Copy link

JanahiX commented Aug 23, 2023

Me too, still there is no solution?

@JanahiX
Copy link

JanahiX commented Aug 31, 2023

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

@nichovski
Copy link

Did anyone solve this issue?

@Emieldv
Copy link

Emieldv commented Jan 25, 2024

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
Copy link

Emieldv commented Jan 25, 2024

This probably also fixes #84

@RobSchilderr
Copy link

RobSchilderr commented Mar 25, 2024

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
Copy link

fmp777 commented Jun 11, 2024

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
Copy link
Member

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants