수색…


Firebase Real-Time 데이터베이스와 Android 애플리케이션의 통합

Android 애플리케이션에 Firebase Real-Time 데이터베이스를 구현하는 방법.

설치 / 설치 :

  1. 먼저, Firebase SDK ( 가이드 )를 설치하십시오.

  2. Firebase 콘솔을 사용하여 프로젝트 등록

  3. 위의 두 단계를 성공적으로 완료 한 후 응용 프로그램 수준에서 다음 종속성을 추가하십시오.

    compile 'com.google.firebase:firebase-database:9.2.1'
    
  4. [선택 사항] 데이터베이스 보안 규칙을 구성합니다 ( 참조 ).

구현 샘플 :

  1. 데이터베이스 참조 선언 및 초기화

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");
    

나중에 다른 참조를 만들어 다른 노드에 액세스 할 수 있습니다.

  1. 데이터베이스에 새 데이터 쓰기

    myRef.setValue("Writing Demo");
    
  2. 데이터베이스에서 데이터 읽기

     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);
         Log.d(TAG, "Value is: " + value);
     }
    
     @Override
     public void onCancelled(DatabaseError error) {
         // Failed to read value
         Log.w(TAG, "Failed to read value.", error.toException());
     }
    });
    


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow