0

I have an Android Library project com.random.lib, and an Android Application project com.random.app. com.random.app is using Library com.random.lib. I've installed com.random.app on my phone.

The Library com.random.lib is registered in Firebase Project FireLib, while Application com.random.app also has its own Firebase Project FireApp.

The com.random.lib is subscribing to awesome topic in FireLib.

FirebaseMessaging.getInstance().subscribeToTopic("awesome");

The com.random.app is subscribing to random topic in FireApp.

FirebaseMessaging.getInstance().subscribeToTopic("random");

However, when I try to push a message to awesome topic from FireLib console, my phone didn't receive the push. When I push a new message to random topic from FireApp console, my phone received the push successfully.

Q: How to receive push message from awesome topic if a message is sent from FireLib?

I've bumped into this solution and I've tried to send a push message directly to a single device using FCM registration token and it works (My phone did receive both push messages from both Firebase projects). However it's not what I want since I need to target the receiver based on the topic.

Community
  • 1
  • 1
zephyrine
  • 51
  • 4
  • I haven't tried implementing it before, but in the scenario you provided, there are two different projects, in order to send a message coming from a different project than the app is associated to. You'll have to grant permission (see my [answer here](http://stackoverflow.com/a/42118836/4625829)) to the FireLib project in order for the device to receive any messages from it. Not sure how you'll do it via the library though. – AL. May 11 '17 at 04:00
  • I do this as workaround: the `com.random.app` needs to generate 2 different tokens (`FireLib` and `FireApp` token), then subscribe each token to preferred topic from associated project using this [link](https://developers.google.com/instance-id/reference/server#create_a_relation_mapping_for_an_app_instance). But I still haven't find a way to do it directly from the Android library though. – zephyrine May 18 '17 at 08:46

1 Answers1

1

If I'm not wrong, this should not be possible. The main package name is com.random.app, as the library doesn't override it. The app will be published under the app's package name, hence it gets notifications for its package name only.

In the case your app would have the package name com.random.lib it could listen for the notifications.

mrpasqal
  • 1,000
  • 1
  • 6
  • 26