[英]Using Firebase Cloud Messaging in Android library project
This is my app folder structure.这是我的应用程序文件夹结构。
Application/ fcm/ FcmMessagingService.class FcmRegistrationService.class google-services.json Android-Manifest.xml
Android-Manifest.xml Android-Manifest.xml
<service android:name=".fcm.FcmRegistrationService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".fcm.FcmMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
This is my library folder structure.这是我的库文件夹结构。
Library(SubModule)/ fcm/ LibMessagingService.class LibRegistrationService.class Android-Manifest.xml
Android-Manifest.xml Android-Manifest.xml
<service android:name=".fcm.LibRegistrationService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".fcm.LibMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
With the above implementation, I can capture the INSTANCE_ID_EVENT
and MESSAGING_EVENT
only from the application's service classes.通过上述实现,我只能从应用程序的服务类中捕获INSTANCE_ID_EVENT
和MESSAGING_EVENT
。 The Firebase service classes in the library module is not at all triggered.库模块中的 Firebase 服务类根本没有被触发。
Is it possible to trigger both the service classes in both Application and Library module when the Firebase messages are received?收到 Firebase 消息时,是否可以同时触发应用程序和库模块中的服务类?
To make it work, I too had to register the library service in Lib manifest as well as App manifest.为了使它工作,我也必须在 Lib manifest 和 App manifest 中注册库服务。 Trying to figure out which actually is required试图弄清楚实际需要哪个
<service android:name="com.libPackage.FCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
I didn't have any problem to implement it on a library module.我在库模块上实现它没有任何问题。 I just implemented all the services in the library and declare them in the client manifest.我刚刚实现了库中的所有服务,并在客户端清单中声明了它们。
This is how my project looks like:这是我的项目的样子:
app java com.example.app MainActivity.java MyApplication.java mylibrary java com.example.library MyFirebaseInstanceIdService.java MyFirebaseMessagingService.java
The google-services.json
file is in the client's app directory. google-services.json
文件位于客户端的应用程序目录中。 Inside the client build.gradle
file, it has the apply plugin: 'com.google.gms.google-services'
.在客户端build.gradle
文件中,它有apply plugin: 'com.google.gms.google-services'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.