【问题标题】:Notification and Database from two different Firebase Application in a single App来自单个应用程序中两个不同 Firebase 应用程序的通知和数据库
【发布时间】:2016-10-11 21:31:17
【问题描述】:

这是我的情况,我已连接到 Firebase 控制台上的 ApplicationA 项目来处理通知。但我也想从 ApplicationB 项目中收听数据库。

问题是我只能有一个google-services.json,我必须在其中一个或另一个之间进行选择,但不能两者都选。所以,我的问题是,我如何指定从另一个应用程序中收听来自google-services.json 的数据库。

自更新以来,项目链接由json内部处理。在更新之前,我可以粘贴我想收听的数据库的整个链接。

这是我目前收听某些数据库路径的方式:

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    fireActionUpdate = database.getReference("org/" + nameId + "/action");
    fireRuleResponse = database.getReference("org/" + nameId + "/notify");

以前:

    fireActionUpdate = new Firebase("https://yellow.firebaseio.com/org/" + nameId + "/action");
    fireRuleResponse = new Firebase("https://yellow.firebaseio.com/org/" + nameId + "/notify");

【问题讨论】:

  • 你仍然可以执行相同的操作,我最近确实为应用程序使用了一个 DB 用于消息传递和 GCM 实现
  • @silverFox - 似乎是一个答案。 Jaythaking - 你试过了吗?
  • @silverFox 的回答有要点。看看我的回答:stackoverflow.com/questions/37634767/…
  • @FrankvanPuffelen 你的答案不起作用-_-,第一条评论是崩溃了,我只是不明白为什么会被接受
  • 重新打开。问题是您有两个进程调用FirebaseDatabase.getInstance(),并且它们正在互相干扰。 Searching for the error message 导致这个答案:stackoverflow.com/questions/37337080/…

标签: android firebase firebase-realtime-database firebase-cloud-messaging


【解决方案1】:

此解决方案是,如果您想将两个应用程序绑定到同一个 Firebase Database,但又想使用 FCM 等所有功能。

请按照以下步骤操作

  1. 从 Firebase 控制台下载两个项目的 google-services.json
  2. 假设 Application A 连接到 Main Database 并且 json 文件是 file1,同样适用于 Application B,数据库是子数据库文件2
  3. 转到 File1 并复制除 project_number& project_id. Basically keep theFirebase_url&&storage_bucket 之外的标题,这两个应用程序都相同。

  4. 同时保持两个项目的 client idapi key 相同。

现在一切就绪。

要连接到Firebase database,请按照以下代码进行操作

        DatabaseReference baseRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://<APP_NAME>.firebaseio.com/");

照常执行其余操作。

希望他们不要推送另一个更新来打破这个规则:D

注意:这些更改已经过测试,我将它用于我的 2 个单独的应用程序,用于集成 FCM 的消息传递

对于我最终遇到的几个已知问题,您可以查看我发布的这段代码Android not receiving Firebase Push Notification - MismatchSenderId

编码愉快!!

【讨论】:

    猜你喜欢
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多