Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Feature request - Expose the SDK for using Pushwoosh with other FCM services #351

Closed simonwatt closed 3 years ago

simonwatt commented 3 years ago

I stopped receiving push notifications on Android. I contacted support who said there was a conflict with a different plugin. Including the following comment:

"Basically, this sample works on every plugin, including the Cordova. Please note that by default, only the implementation with the highest priority can handle push notifications, and, as your custom implementation is located above ours in the final AndroidManifest.xml, it intercepts all received pushes, so you have to manually pass them to our SDK."

With a link to:

https://docs.pushwoosh.com/platform-docs/pushwoosh-sdk/android-push-notifications/customizing-android-sdk/android-faq#using-pushwoosh-sdk-with-other-fcm-services

I removed plugins one by one and inspected the Android manifest and worked out the conflicting plugin was cordova-plugin-firebasex which is 'stealing' the notifications from pushwoosh.

Unfortunately, I don't believe the advice that the above sample works with Cordova is correct (short of forking the plugin, and modifying native Android code on my fork). I've checked the source code of this plugin and I can't see any methods that expose a way to implement a router service as per the example?

wfhm commented 3 years ago

@simonwatt Hey,

I just tested the solution provided by our support team, and it seems to be working fine, it just requires an additional step you have to perform in a native Android project (located in root/platforms/android).

  1. Open Android project generated by Cordova and create a class - let's call it MyFcmService - in src/main/java/your/package/name directory (i.e. src/main/java/com/pushwoosh/demoapp/MyFcmService).
  2. Edit its code as below (change package name to yours):
    
    package com.pushwoosh.demoapp;

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

public class MyFcmService extends FirebaseMessagingService{

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    PushwooshFcmHelper.onMessageReceived(this, remoteMessage);
}

@Override
public void onNewToken(String s) {
    super.onNewToken(s);
    PushwooshFcmHelper.onTokenRefresh(s);
}

}

3. Open AndroidManifest.xml (located in **app/src/main**) and add the following lines under the <application> tag:

<service android:name=".MyFcmService">

    </service>

After that, just build the app, and that should be it. If, for some reason, FirebaseMessagingService and PushwooshFcmHelper classes are not accessible, check that you have the following lines in app-level build.gradle (they should be added there automatically though):

implementation "com.pushwoosh:pushwoosh-firebase:6.2.8" implementation "com.google.firebase:firebase-messaging:(+,19.0.0)"