简体   繁体   English

android:fcm在库模块中

[英]android: fcm in library module

I am facing a weird issue integrating Firebase Cloud Messaging in a library module. 我正面临着将Firebase Cloud Messaging集成到库模块中的一个奇怪问题。 I am working on a library project in which I need to handle notifications right coming from the FCM Server from the library itself. 我正在开发一个库项目,我需要从库本身处理来自FCM服务器的通知。 I am not aware if it is possible or not. 我不知道是否可能。

Steps I followed: 我遵循的步骤:

  • I created Project on Firebase Console. 我在Firebase控制台上创建了Project。
  • Inside the project, I created app with package same as my library package. 在项目内部,我使用与我的库包相同的包创建了应用程序。
  • I downloaded and put google-services.json in library module. 我下载并将google-services.json放入库模块中。
  • I have applied the dependency in gradle of library module. 我已经在库模块的gradle中应用了依赖项。
  • Now, I have initialized my library module in app module. 现在,我已经在app模块中初始化了我的库模块。 I am also getting log of generated device token from FirebaseInstanceIdService . 我还从FirebaseInstanceIdService获取生成的设备令牌的日志。

Problem: When I try to send push from Firebase Console, I am not receiving any Notification. 问题:当我尝试从Firebase控制台发送推送时,我没有收到任何通知。

Have anyone faced such issue and could help me with this ? 有没有人遇到这样的问题,可以帮助我吗?

So, after running a lot through trial and error method, I succeeded in getting Notifications. 所以,经过试错法运行后,我成功获得了通知。

Things to be noted: 需要注意的事项:

  • You cannot just integrate Firebase Cloud Notifications in library module. 您不能只在库模块中集成Firebase云通知。
  • Client app module who will be using this library module will have google-services.json file in his directory and not in library module directory. 将使用此库模块的客户端应用程序模块将在其目录中具有google-services.json文件,而不是在库模块目录中。
  • Client app module gradle will be having below line in it and not in library module gradle: 客户端应用程序模块gradle将在其下面的行中而不是在库模块gradle中:

apply plugin: 'com.google.gms.google-services' 申请插件:'com.google.gms.google-services'

So, once I made those two changes, I was able to get Notifications. 所以,一旦我做了这两个更改,我就能得到通知。

FCM clients require devices running Android 2.3 or higher that also have the Google Play Store app installed, or an emulator running Android 2.3 with Google APIs. FCM客户端要求安装了Android 2.3或更高版本且安装了Google Play商店应用的设备,或运行带有Google API的Android 2.3的模拟器。

If you are Using an Emulator Please Check whether Google APIs were installed or Not. 如果您使用的是仿真器,请检查是否已安装Google API。

Integrating FCM using Android Studio is very easy, You have to only , Tool->>Firebase->>on the Right panel ->>Choose cloud Messaging. 使用Android Studio集成FCM非常简单,只需在右侧面板上选择工具 - >> Firebase - >> - 选择云消息传递。 Setup-->Firebase cloud messaging. 设置 - > Firebase云消息传递。

Then you have to follow point number 1,2,3. 然后你必须遵循1,2,3号点。 And you have to also register your app to Firebase console also as you already status. 您还必须将您的应用注册到Firebase控制台,因为您已经处于状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM