我目前正在尝试在我们的应用程序中实现推送通知。
所以我们有三个模块。
我给了他们明显的名字。应用程序1和2依赖于逻辑模块。此模块包含两个应用程序的所有逻辑。现在,我希望向在App 1或App 2上登录的用户发送特定于应用的通知。
问题:
我无法将firebase逻辑放入Logic模块,因为此模块配置为lib模块,未配置为App。现在我必须将firebase逻辑放在App 1和2中,但我无法从Logic模块访问此逻辑,因为App 1和2依赖于Logic模块,而不是相反。
Firebase需要为每个连接的应用程序提供google-services.json,此文件需要生成用户特定的pushtoken。
有没有办法配置这个,以便我可以为推送通知生成用户特定的令牌?因此,在用户登录后必须根据应用程序和用户生成pushtoken,以便该用户可以在他/她登录的所述设备上获得通知。
我希望这很清楚。
应该没有什么能阻止你实现你所描述的内容。
您仍然可以将Firebase SDK依赖项添加到库模块。你不能在它上面使用google-services插件 - 它只属于应用程序模块。
更新的答案:您可以创建与应用客户端分离的Firebase Cloud Notifications模块要使其正常工作,您必须:
在模块(库):
implementation 'com.google.firebase:firebase-messaging:17.6.0'
<service android:name=".firebase.YourNotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
在Android Manifest文件中。
在您的应用客户端上:
apply plugin: 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation'com.google.firebase:firebase-messaging:17.6.0'
classpath 'com.google.gms:google-services:4.2.0'
就是这样。那可行。