Push notifications not working for Android
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
- Install and configure @capacitor/push-notifications
- Enable Cloud Messaging API in Firebase (legacy) and add the Server key to Intercom (Settings > Install > Android > Push)
- Install and configure this plugin
- Add app code:
import { Intercom } from '@capacitor-community/intercom'; import { PushNotifications } from '@capacitor/push-notifications'; PushNotifications.requestPermissions(); PushNotifications.register(); Intercom.registerUnidentifiedUser(); Intercom.displayLauncher(); - 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!
I have the same issue here, it works on iOS but doesn't work in Android.
Me too, still there is no solution?
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
Did anyone solve this issue?
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:
- Add a file called
CustomMessagingPlugin.javatoandroid/app/src/main/java/<com>/<appname>/<app>(This should be the same place where the MainActivity.java file is located)
- 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);
}
}
}
- 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>
- 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 🤷♂️
This probably also fixes #84
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?
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()?
Is there a reason this package uses @capacitor/push-notifications vs Intercom.registerPush()?
not that I recall. That would be a reasonable change.
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