是否可以将Firebase数据库连接到不同的Firebase项目? [英] Is it possible to connect to a Firebase Database to a different Firebase Project?

查看:93
本文介绍了是否可以将Firebase数据库连接到不同的Firebase项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个android应用程序(A和B),两个在Firebase上都有单独的项目,目前我正在开发一个功能,让我使用FCM在应用程序A和应用程序B之间发送消息。由于这两个应用程序都在不同的项目中,所以我无法做到这一点,并且由于其他原因无法将这两个应用程序都放在一个项目中。



所以我在想如果我可以在应用程序A中创建一个消息表,并从应用程序B访问相同的消息,并实现我的消息功能。可以这样做吗?如果是,请给我一些信息?如果没有一个替代方案?



谢谢

解决方案

能够通过显式提供配置数据访问其他数据库:

  FirebaseOptions options = new FirebaseOptions.Builder()
.setApiKey(AI ... j0)
.setApplicationId(1:5 ... e0)//我不确定这是否需要
.setDatabaseUrl(https ://myapp.firebaseio.com)
.build();
FirebaseApp app = FirebaseApp.initializeApp(getApplicationContext(),options,app);
FirebaseDatabase数据库= FirebaseDatabase.getInstance(app);


I have two android apps (A and B) and both have separate projects on Firebase, Currently I am working on a feature which would lets me send messages between app A and app B using FCM. Due to both apps being in different projects, I am unable to do this and It is not possible to put both the apps on a single project due to some other reason.

So I was thinking if I could create a messages table in app A and access the same from app B and implement my messaging feature. Is it possible to do this? if yes, can you please give me some info? if no is there an alternative?

thanks

解决方案

You should be able to access the "other" database by explicitly providing the configuration data:

FirebaseOptions options = new FirebaseOptions.Builder()
        .setApiKey("AI...j0")
        .setApplicationId("1:5...e0") // I'm not certain this is needed
        .setDatabaseUrl("https://myapp.firebaseio.com")
        .build();
FirebaseApp app = FirebaseApp.initializeApp(getApplicationContext(), options, "app");
FirebaseDatabase database = FirebaseDatabase.getInstance(app);

这篇关于是否可以将Firebase数据库连接到不同的Firebase项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆