Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

How to use this library when you have multiple push providers? #952

Closed
@shercoder

Description

@shercoder

I'm using react-native-push-notification along with Localytics push messaging. So I created a custom FirebaseMessagingService that checks if RemoteMessage is a Localytics message else it needs to fire RNPushListenerService.

I'm starting RNPushListenerService using startService but it does not look like it is starting it. Has anyone else dealt with issue like this before? and How did you handle it?

Note: There can only be one FirebaseMessagingService with intent-filter of com.google.firebase.MESSAGING_EVENT and I'm registering my custom service with that intent-filter.

public class CustomFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> data = remoteMessage.getData();
        try {
            if (!Localytics.handleFirebaseMessage(data)) {
                forwardPushNotification(remoteMessage);
            }
        } catch (Exception e) {
            Timber.e(e, "Failed to extract Push Message", remoteMessage.getMessageId());
        }
    }

    @Override
    public void onNewToken(String token) {
        super.onNewToken(token);
        Localytics.setPushRegistrationId(token);
    }

    private void forwardPushNotification(RemoteMessage remoteMessage) {
        Map<String, String> data = remoteMessage.getData();
        data.put("from", remoteMessage.getFrom());
        Intent intent = new Intent(this, RNPushNotificationListenerService.class);
        intent.setAction("com.google.firebase.MESSAGING_EVENT");
        Bundle extraData = new Bundle(data.size());
        for (Map.Entry<String, String> entry : data.entrySet()) {
            extraData.putString(entry.getKey(), entry.getValue());
        }
        intent.putExtras(extraData);
        startService(intent);
    }
}

I think react-native-push-notification library needs to provide a custom method like the one Localytics is providing to handle these notifications when the user has multiple push providers. e.g. Localytics.handleFirebaseMessage

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions