Firebase push notifications on Android with multip

2019-06-25 06:31发布

问题:

I'm currently trying to implement push notifications in our application.

So we have three modules.

  • App 1
  • Logic
  • App 2

I gave them obviously names. App 1 and 2 have a dependency on the logic module. This module contains ALL the logic for both apps. Now I want App specific notifications to users that are logged in on App 1 OR App 2.

Problem:

I can't put the firebase logic into the Logic module since this module is configured as a lib module and isn't configured as an App. Now I have to put the firebase logic in App 1 and 2, but I can't access this logic from the Logic module since App 1 and 2 have a dependency on the Logic module and not the other way around.

Firebase requires a google-services.json for every app connected, this file is required to generate a user specific pushtoken.

Is there a way to configure this so that I can generate user specific tokens for push notifications? So after a user logs in a pushtoken has to be generated according to the App and user so this user can get a notifcation on said device which he/she is logged in.

I hope this is clear enough.

回答1:

There should be nothing stopping you from implementing what you're describing.

You can still add Firebase SDK dependencies to a library module. You just can't use the google-services plugin on it - that belongs only on application modules.



回答2:

A more updated answer: You CAN create a module of Firebase Cloud Notifications separated from an app client To make it work you have to:

On Module (Library):

  • Add implementation 'com.google.firebase:firebase-messaging:17.6.0' in module gradle file
  • Add

    <service android:name=".firebase.YourNotificationService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

in the Android Manifest file.

On your app client:

  • Add apply plugin: 'com.google.gms.google-services' on the last line in your module gradle file
  • Add implementation 'com.google.firebase:firebase-core:16.0.8' in your module gradle file
  • Add implementation'com.google.firebase:firebase-messaging:17.6.0' in your module gradle file
  • Add classpath 'com.google.gms:google-services:4.2.0' inside "dependencies" block of your project gradle file
  • Add your "google-services.json" file inside your "app" folder

And that's it. That will work.