{"id":1082,"date":"2021-01-19T11:32:10","date_gmt":"2021-01-19T03:32:10","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=1082"},"modified":"2021-01-19T11:33:12","modified_gmt":"2021-01-19T03:33:12","slug":"android-firebase-cloud-firestore","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-firebase-cloud-firestore\/","title":{"rendered":"Android Firebase Cloud Firestore"},"content":{"rendered":"<h4>1.Firebase\u8207\u5c08\u6848\u9023\u7d50<\/h4>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/03\/FCM1.png\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/03\/FCM1-198x300.png\" alt=\"\" \/><\/a><\/p>\n<h4>2.\u9ede\u64caCloud Firestore\u5c07library\u8207google-services.json\u5c0e\u5165\u9032\u5c08\u6848<\/h4>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_5855c94636983c3eade8da82b9f71618.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_5855c94636983c3eade8da82b9f71618.jpg\" alt=\"\" \/><\/a><\/p>\n<h4>3.Firebase console\u5275\u5efa\u8cc7\u6599\u5eab<\/h4>\n<h5>\u9078\u64c7(\u6e2c\u8a66\u6a21\u5f0f\u555f\u52d5) \u4e0a\u67b6\u524d\u5728\u6539\u70ba(\u9396\u5b9a\u6a21\u5f0f\u555f\u52d5)<\/h5>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_b12c6ebcde01c081c3ddebd827a88c82.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_b12c6ebcde01c081c3ddebd827a88c82.jpg\" alt=\"\" \/><\/a><\/p>\n<h4>4.\u5beb\u5165\u8cc7\u6599<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">private val users = mutableListOf&lt;Map&lt;String, String&gt;&gt;()\nprivate val database = FirebaseFirestore.getInstance()\n\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.activity_main)\n\n    users.add(insertUser(\"fly\", \"a123456\"))\n    users.add(insertUser(\"wei\", \"b123456\"))\n\n    for (user in users) {\n        database.collection(\"users\")\n            .add(user)\n            .addOnSuccessListener {\n                Log.e(\"GGG\", it.id)\n            }\n            .addOnFailureListener {\n                Log.e(\"GGG\", it.toString())\n            }\n    }\n}\n\nprivate fun insertUser(name: String, password: String): Map&lt;String, String&gt; {\n    return mapOf(\"name\" to name, \"password\" to password)\n}\n<\/code><\/pre>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_92c1465e8dfae9cd6fb37a05bf8bcf35.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_92c1465e8dfae9cd6fb37a05bf8bcf35.jpg\" alt=\"\" \/><\/a><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_a43805a1e8b1afcb32810cef1f6716ef.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_a43805a1e8b1afcb32810cef1f6716ef.jpg\" alt=\"\" \/><\/a><\/p>\n<h5>\u56de\u50b3\u7684document id<\/h5>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_d33908c084040d1844d02e185ce59bd6.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_d33908c084040d1844d02e185ce59bd6.jpg\" alt=\"\" \/><\/a><\/p>\n<h4>5.\u8b80\u53d6\u8cc7\u6599<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">private val database = FirebaseFirestore.getInstance()\n\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.activity_main)\n\n    database.collection(\"users\")\n        .get().addOnSuccessListener {\n            val users = it.toObjects(User::class.java)\n            users.forEach {user -&gt;\n                Log.e(\"GGG\", \"<span class=\"katex math inline\">{user.name}<\/span>{user.password}\")\n            }\n        }\n}\n<\/code><\/pre>\n<h4>6.Model(\u4e00\u5b9a\u8981\u6709\u7a7a\u5efa\u69cb\u5b50)<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">class User(val name: String, val password: String)  {\n    constructor() : this(\"\", \"\")\n}\n<\/code><\/pre>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_1bd6abe9c78ef6c63a71fc9afc156ad6.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2021\/01\/wp_editor_md_1bd6abe9c78ef6c63a71fc9afc156ad6.jpg\" alt=\"\" \/><\/a><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.Firebase\u8207\u5c08\u6848\u9023\u7d50 2.\u9ede\u64caCloud Firestore\u5c07library\u8207google-serv &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[34],"tags":[13,167,40],"class_list":["post-1082","post","type-post","status-publish","format-standard","hentry","category-firebase","tag-android","tag-cloud-firestore","tag-firebase"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=1082"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1082\/revisions"}],"predecessor-version":[{"id":1085,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1082\/revisions\/1085"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=1082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=1082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=1082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}