我创建了一个 Firebase,并且可以将数据写入身份验证。
但是,我无法将数据写入实时数据库。
- I have connected to Firebase
- 我已经添加了实时数据库
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.4.1')
// Declare the dependency for the Realtime Database library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-database:20.0.2'
- 我已经将读写规则设置为true
{
"rules": {
".read": true,
".write": true
}
}
I tried this to write data into Firebase but I get noting
![enter image description here](https://i.stack.imgur.com/BehaZ.png)
// Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
// Write a message to the database
FirebaseDatabase.getInstance().getReference().child("aaa").child("bbb").setValue("ccc");
FirebaseDatabase.getInstance().getReference().child("aaa").child("bbb").setValue("ccc");
编写的代码看起来没问题,所以我认为问题可能出在其他地方。
如果您创建了 Firebase 控制台after你下载了google-services.json
文件,该文件将不包含正确的 URL,并且 SDK 可能无法在服务器上找到您的数据库。
要解决该问题,您可以:
- 下载更新的
google-services.json
并在您的应用程序中使用它,或者
- 在代码中提供数据库 URL
FirebaseDatabase database = FirebaseDatabase.getInstance("database URL here");
另请参阅:由于一切设置正确,Google Firebase 实时数据库无法工作 https://stackoverflow.com/questions/68173632/google-firebase-real-time-database-not-working-as-everything-is-set-correctly/68179677#68179677
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)