터미널에 대한 메시지를 받았기 때문에 Firebase에 연결한 것 같습니다.
I/FirebaseInitProvider: FirebaseApp initialization successful
그리고 나는 규칙을 올바르게 설정했다고 생각합니다.
{
"rules": {
".read": true,
".write": true
}
}
여기에 내 읽기 및 쓰기 code가 있습니다.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Write a message to the database
FirebaseDatabase database= FirebaseDatabase.getInstance();
DatabaseReference myRef= database.getReference("message");
myRef.setValue("Hello, World!");
}
@Override
protected void onStart() {
super.onStart();
//Read from the database
FirebaseDatabase database= FirebaseDatabase.getInstance();
DatabaseReference myRef= database.getReference("message");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//This method is called once with the initial value and again
//whenever data at this location is updated.
String value= dataSnapshot.getValue(String.class);
System.out.println(value);
Log.d("T", "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
//Failed to read value
Log.w("F", "Failed to read value.", error.toException());
}
});
}
}
그리고 매우 이상한 점은 값을 인쇄할 수 있지만 데이터는 콘솔에서 업데이트되지 않는다는 것입니다.
인쇄된 값
I/System.out: Hello, World!
D/T: Value is: Hello, World!
하지만 콘솔에서...
네, 콘솔에서...
Lucas Timothy2022-01-31 17:59:37
데이터가 업데이트되지 않는다는 것은 무엇을 의미합니까? 콘솔에 아무것도 표시되지 않습니까?
Hasan Bou Taam2022-01-31 17:59:37