How to have multiple FirebaseMessagingService in Android?
In my project, I'm using two libs to handle two different types of push notifications: Localytics and react-native-push-notification.
I have a custom FirebaseMessagingService that checks if it's a Localytics push then let the Localytics handle it via their provided methods. But if it's not a Localytics push, I need to pass this push data to react-native-push-notification's RNPushNotificationListenerService which is also a FirebaseMessagingService.
I'm attempting to start the RNPushNotificationListenerService but it doesn't seem to be starting because it never sends a push. I have tried setting breakpoints too but no luck.
AndroidManifest.xml
<!-- push notifications -->
<service android:name=".fcm.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- push notifications end -->
CustomFirebaseMessagingService.java
public class CustomFirebaseMessagingService extends FirebaseMessagingService {
public CustomFirebaseMessagingService() {
super();
}
@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 onDeletedMessages() {
super.onDeletedMessages();
}
@Override
public void onMessageSent(String msgId) {
super.onMessageSent(msgId);
}
@Override
public void onSendError(String msgId, Exception e) {
super.onSendError(msgId, e);
}
@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);
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 have a feeling I'm not starting the service correctly?
I am also aware that AndroidManifest will ignore the declaration of com.google.firebase.MESSAGING_EVENT
for RNPushNotificationListenerService
.
I have tried getting the individual libraries working without my custom FirebaseMessagingService and they both work correctly. I just need to figure out how to start RNPushNotificationListenerService when I have both setup with my custom FirebaseMessagingService.
android firebase react-native firebase-cloud-messaging react-native-push-notification
add a comment |
In my project, I'm using two libs to handle two different types of push notifications: Localytics and react-native-push-notification.
I have a custom FirebaseMessagingService that checks if it's a Localytics push then let the Localytics handle it via their provided methods. But if it's not a Localytics push, I need to pass this push data to react-native-push-notification's RNPushNotificationListenerService which is also a FirebaseMessagingService.
I'm attempting to start the RNPushNotificationListenerService but it doesn't seem to be starting because it never sends a push. I have tried setting breakpoints too but no luck.
AndroidManifest.xml
<!-- push notifications -->
<service android:name=".fcm.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- push notifications end -->
CustomFirebaseMessagingService.java
public class CustomFirebaseMessagingService extends FirebaseMessagingService {
public CustomFirebaseMessagingService() {
super();
}
@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 onDeletedMessages() {
super.onDeletedMessages();
}
@Override
public void onMessageSent(String msgId) {
super.onMessageSent(msgId);
}
@Override
public void onSendError(String msgId, Exception e) {
super.onSendError(msgId, e);
}
@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);
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 have a feeling I'm not starting the service correctly?
I am also aware that AndroidManifest will ignore the declaration of com.google.firebase.MESSAGING_EVENT
for RNPushNotificationListenerService
.
I have tried getting the individual libraries working without my custom FirebaseMessagingService and they both work correctly. I just need to figure out how to start RNPushNotificationListenerService when I have both setup with my custom FirebaseMessagingService.
android firebase react-native firebase-cloud-messaging react-native-push-notification
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17
add a comment |
In my project, I'm using two libs to handle two different types of push notifications: Localytics and react-native-push-notification.
I have a custom FirebaseMessagingService that checks if it's a Localytics push then let the Localytics handle it via their provided methods. But if it's not a Localytics push, I need to pass this push data to react-native-push-notification's RNPushNotificationListenerService which is also a FirebaseMessagingService.
I'm attempting to start the RNPushNotificationListenerService but it doesn't seem to be starting because it never sends a push. I have tried setting breakpoints too but no luck.
AndroidManifest.xml
<!-- push notifications -->
<service android:name=".fcm.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- push notifications end -->
CustomFirebaseMessagingService.java
public class CustomFirebaseMessagingService extends FirebaseMessagingService {
public CustomFirebaseMessagingService() {
super();
}
@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 onDeletedMessages() {
super.onDeletedMessages();
}
@Override
public void onMessageSent(String msgId) {
super.onMessageSent(msgId);
}
@Override
public void onSendError(String msgId, Exception e) {
super.onSendError(msgId, e);
}
@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);
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 have a feeling I'm not starting the service correctly?
I am also aware that AndroidManifest will ignore the declaration of com.google.firebase.MESSAGING_EVENT
for RNPushNotificationListenerService
.
I have tried getting the individual libraries working without my custom FirebaseMessagingService and they both work correctly. I just need to figure out how to start RNPushNotificationListenerService when I have both setup with my custom FirebaseMessagingService.
android firebase react-native firebase-cloud-messaging react-native-push-notification
In my project, I'm using two libs to handle two different types of push notifications: Localytics and react-native-push-notification.
I have a custom FirebaseMessagingService that checks if it's a Localytics push then let the Localytics handle it via their provided methods. But if it's not a Localytics push, I need to pass this push data to react-native-push-notification's RNPushNotificationListenerService which is also a FirebaseMessagingService.
I'm attempting to start the RNPushNotificationListenerService but it doesn't seem to be starting because it never sends a push. I have tried setting breakpoints too but no luck.
AndroidManifest.xml
<!-- push notifications -->
<service android:name=".fcm.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- push notifications end -->
CustomFirebaseMessagingService.java
public class CustomFirebaseMessagingService extends FirebaseMessagingService {
public CustomFirebaseMessagingService() {
super();
}
@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 onDeletedMessages() {
super.onDeletedMessages();
}
@Override
public void onMessageSent(String msgId) {
super.onMessageSent(msgId);
}
@Override
public void onSendError(String msgId, Exception e) {
super.onSendError(msgId, e);
}
@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);
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 have a feeling I'm not starting the service correctly?
I am also aware that AndroidManifest will ignore the declaration of com.google.firebase.MESSAGING_EVENT
for RNPushNotificationListenerService
.
I have tried getting the individual libraries working without my custom FirebaseMessagingService and they both work correctly. I just need to figure out how to start RNPushNotificationListenerService when I have both setup with my custom FirebaseMessagingService.
android firebase react-native firebase-cloud-messaging react-native-push-notification
android firebase react-native firebase-cloud-messaging react-native-push-notification
asked Nov 28 '18 at 18:55
SherCoderSherCoder
3481821
3481821
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17
add a comment |
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526265%2fhow-to-have-multiple-firebasemessagingservice-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526265%2fhow-to-have-multiple-firebasemessagingservice-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do you need two NotificationService?
– Pedro Massango
Nov 28 '18 at 19:39
@PedroMassango I have two push providers that I need to use. Project requirement.
– SherCoder
Nov 28 '18 at 21:17