728x90
반응형
SMALL
package com.example.firestoretest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
class MainActivity : AppCompatActivity() {
val db = Firebase.firestore
var mDocRef: DocumentReference? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getCloudFirebase()
realTimeCloudFirebaseListener()
}
private fun getCloudFirebase() {
val docRef = db.collection("Main").document("submain")
docRef.get()
.addOnSuccessListener { document ->
if (document != null) {
Log.d("TAGTAG", "DocumentSnapshot data: ${document.data}")
} else {
Log.d("TAGTAG", "No")
}
}
.addOnFailureListener { exception ->
Log.d("TAGTAG", "message: ${exception.message}")
}
}
private fun realTimeCloudFirebaseListener() {
val docRef = db.collection("Main").document("submain")
docRef.addSnapshotListener { snapshot, e ->
if (e != null) {
Log.d("TAGTAG", "realTimeCloudFirebaseListener / Listen Failed")
return@addSnapshotListener
}
if (snapshot != null && snapshot.exists()) {
Log.d("TAGTAG", "realTimeCloudFirebaseListener / snapshot data: ${snapshot.data}")
} else {
Log.d("TAGTAG", "no")
}
}
}
}
'Android Study' 카테고리의 다른 글
Button 에 rippple efect 적용하기 (0) | 2023.08.29 |
---|---|
Android WebView 연동시키기 step-1 (0) | 2023.08.28 |
TextView 문자열, 클래스에서 원하는 부분만 스타일 변경하여 적용시키기(Feat. Kotlin) (0) | 2023.08.17 |
SHA-1 key 얻는방법 (for Mac, Debug) (0) | 2023.06.19 |
xml -> bitmap 변환 하기 (feat.Kakao map Marker) (0) | 2023.01.26 |