[{"data":1,"prerenderedAt":955},["ShallowReactive",2],{"news-item-\u002Fnews\u002Fandroid-firebase-for-beginer":3},{"id":4,"title":5,"body":6,"category":940,"created by":943,"date":944,"description":945,"extension":946,"meta":947,"navigation":948,"path":949,"sections":950,"seo":951,"stem":952,"thumbnail":953,"__hash__":954},"content_en\u002Fnews\u002Fandroid-firebase-for-beginer.md","Android Firebase for beginers",{"type":7,"value":8,"toc":921},"minimark",[9,18,23,35,39,46,56,65,71,75,85,95,99,115,134,140,150,154,162,166,176,180,184,189,192,196,219,224,234,238,243,247,259,263,289,299,312,316,323,327,333,337,351,353,357,368,370,374,381,384,399,401,405,409,412,415,418,432,436,441,447,455,459,470,474,482,486,500,504,509,515,519,540,547,553,557,564,570,574,584,590,594,597,601,609,615,623,627,650,654,661,665,674,679,692,700,704,709,713,726,728,732,736,739,742,745,755,759,764,768,776,781,787,792,799,804,807,813,819,822,828,831,837,844,848,853,859,863,868,874,878,883,889,893,897,903,909,915],[10,11,14],"h1",{"style":12,"id":13},"text-align:center;","firebase",[15,16,17],"strong",{},"Firebase",[19,20,22],"h2",{"id":21},"i-what-is-firebase","I. What is Firebase",[24,25,26,27,34],"p",{},"Google Firebase is a Google-backed application development software that enables developers to develop iOS, Android and ",[28,29,33],"a",{"href":30,"rel":31},"https:\u002F\u002Fsearchsoftwarequality.techtarget.com\u002Fdefinition\u002FWeb-application-Web-app",[32],"nofollow","Web apps",". Firebase provides tools for tracking analytics, reporting and fixing app crashes, creating marketing and product experiment. Firebase has many services and today I'm going to introduce to in-app messaging, cloud messages and real-time databases.",[19,36,38],{"id":37},"ii-add-firebase-to-your-app","II. Add Firebase to your app",[24,40,41,42],{},"Before you integrate Firebase into your Android app, you need to create a Firebase project to connect to your Android app. log in to Firebase console in this link ",[28,43,44],{"href":44,"rel":45},"https:\u002F\u002Fconsole.firebase.google.com\u002F?hl=en",[32],[24,47,48,51,52,55],{},[15,49,50],{},"Step 1",": After you signed-in to Firebase, click on \"",[15,53,54],{},"Create a project","\".",[57,58],"img",{"className":59,"alt":62,"src":63,"style":64},[60,61],"block","mx-auto","","https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075255\u002FScreen-Shot-2020-02-20-at-9.31.55-AM.png","width: 100%;",[24,66,67,70],{},[15,68,69],{},"Step 2",": There are steps to take to create a new Firebase project. Click on Android icon.",[57,72],{"className":73,"alt":62,"src":74,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075332\u002FScreen-Shot-2020-02-20-at-9.43.53-AM.png",[24,76,77,80,81,84],{},[15,78,79],{},"Step 3",": Enter your \"",[15,82,83],{},"Android package name","\" the same as package name in AndroidManifest",[24,86,87,92],{},[57,88],{"className":89,"alt":62,"src":90,"style":91},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075551\u002FScreen-Shot-2020-02-21-at-3.19.26-PM.png","width: 70%;",[93,94],"br",{},[57,96],{"className":97,"alt":62,"src":98,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075616\u002FScreen-Shot-2020-02-20-at-9.51.12-AM-1024x121.png",[24,100,101,104,105,108,109,113],{},[15,102,103],{},"Step 4",":  Download \"",[15,106,107],{},"google-services.json\""," and add to the project.\n",[57,110],{"className":111,"alt":62,"src":112,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075822\u002FScreen-Shot-2020-02-21-at-3.20.06-PM.png",[93,114],{},[24,116,117,118,121,122,127,128,130],{},"Click on Project to switch view, you will see the root directory of the project . Put the \"",[15,119,120],{},"google-services.json","\" file into  \"Project\u002F~\u002Fapp\" folder.\n",[57,123],{"className":124,"alt":62,"src":125,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075857\u002FScreen-Shot-2020-02-20-at-9.56.43-AM.png","width: 50%;"," ",[93,129],{},[57,131],{"className":132,"alt":62,"src":133,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07075949\u002FScreen-Shot-2020-02-20-at-9.58.50-AM.png",[24,135,136,139],{},[15,137,138],{},"Step 5",": Add Firebase SDK.",[24,141,142,145,146,149],{},[15,143,144],{},"1."," In \"",[15,147,148],{},"build.gradle","\" (Project):",[57,151],{"className":152,"alt":62,"src":153,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080017\u002FScreen-Shot-2020-02-20-at-10.06.20-AM-1024x479.png",[24,155,156,145,159,161],{},[15,157,158],{},"2.",[15,160,148],{},"\" (app):",[57,163],{"className":164,"alt":62,"src":165,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080017\u002FScreen-Shot-2020-02-20-at-10.06.20-AM.png",[24,167,168,171,172,175],{},[15,169,170],{},"Step 6",": Run and wait Firebase verify the app, you will see message when success, click on “",[15,173,174],{},"Continue to console","”.",[57,177],{"className":178,"alt":62,"src":179,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080122\u002FScreen-Shot-2020-02-19-at-4.31.20-PM-31.png",[19,181,183],{"id":182},"iiiin-app-message","III. In-App Message",[185,186,188],"h3",{"id":187},"_1-introduction","1. Introduction",[24,190,191],{},"Firebase In-App Messaging helps you engage your app's active users by sending them targeted, contextual messages that encourage them to use key app features. For example, you could send an in-app message to get users to subscribe, watch a video, complete a level, or buy an item. You can customize messages as cards, banners, modals, or images, and set up triggers so that they appear exactly when they'd benefit your users most.",[185,193,195],{"id":194},"_2-get-start","2. Get start",[24,197,198,200,201,127,204,207,208,210,211,214,215],{},[15,199,50],{},": Add “",[15,202,203],{},"implementation",[15,205,206],{},"‘com.google.firebase:firebase-inappmessaging-display:19.0.3’"," into \"",[15,209,148],{},"\" (app) and Click \"",[15,212,213],{},"Sync Now","\". ",[57,216],{"className":217,"alt":62,"src":218,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080223\u002FScreen-Shot-2020-02-19-at-4.51.31-PM-33-1024x641.png",[24,220,221,223],{},[15,222,69],{},": Get Firebase instance ID (this id's used to test in-app message on Firebase).",[225,226,231],"pre",{"className":227,"code":229,"language":230},[228],"language-text","private fun createInstanceId() {\n    FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener { task ->\n        if (!task.isSuccessful) {\n            Log.w(TAG, \"getInstanceId failed\", task.exception)\n            return@addOnCompleteListener\n        }\n\n        \u002F\u002Fcreate new instance id Token\n        val msg = task.result?.id\n        Log.d(TAG, \"token: $msg\")\n    }\n}\n","text",[232,233,229],"code",{"__ignoreMap":62},[57,235],{"className":236,"alt":62,"src":237,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080253\u002FScreen-Shot-2020-02-19-at-5.01.04-PM-35-1024x417.png",[24,239,240,242],{},[15,241,79],{},": Run the app and open \"Logcat\" tool, we will see the ID token.",[57,244],{"className":245,"alt":62,"src":246,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080319\u002FScreen-Shot-2020-02-19-at-5.23.36-PM-51-1024x625.png",[24,248,249,251,252,255,256,175],{},[15,250,103],{},": Copy the ID token, open Firebase console -> \"",[15,253,254],{},"In-App Messaging","\", click “",[15,257,258],{},"Create your first campaign",[57,260],{"className":261,"alt":62,"src":262,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080401\u002FScreen-Shot-2020-02-19-at-5.06.23-PM-41-1024x606.png",[24,264,265,267,268,271,272,275,276,279,280,284,285],{},[15,266,138],{},": Enter \"",[15,269,270],{},"Message title","\" (ex: Hello I'm FireBase), \"",[15,273,274],{},"Body","\" (optional), \"",[15,277,278],{},"Images","\" (ex: ",[28,281,282],{"href":282,"rel":283},"https:\u002F\u002Fcdn.pixabay.com\u002Fphoto\u002F2015\u002F10\u002F12\u002F14\u002F54\u002Fcoffee-983955_960_720.jpg",[32],") ",[57,286],{"className":287,"alt":62,"src":288,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080500\u002FScreen-Shot-2020-02-19-at-5.12.17-PM-45-1.png",[24,290,291,292,214,295],{},"Add \"",[15,293,294],{},"Button text",[57,296],{"className":297,"alt":62,"src":298,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080533\u002FScreen-Shot-2020-02-19-at-5.12.47-PM-47.png",[24,300,301,303,304,307,308,311],{},[15,302,170],{},": Click “",[15,305,306],{},"Test on Device","”, and paste the ID token into \"",[15,309,310],{},"Add an instance ID","\" field.",[57,313],{"className":314,"alt":62,"src":315,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080559\u002FScreen-Shot-2020-02-19-at-5.17.37-PM-49.png",[24,317,318,319,322],{},"Firebase In-App Messaging sends the test message as soon as you click \"",[15,320,321],{},"Test","\". To see it, move the app to background, then re-open the app on your testing device.",[57,324],{"className":325,"alt":62,"src":326,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080625\u002FScreen-Shot-2020-02-19-at-5.24.22-PM-53-1024x663.png",[24,328,329,332],{},[15,330,331],{},"Result",":",[57,334],{"className":335,"alt":62,"src":336,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080648\u002FScreenshot_20200219-173204-57-768x1365.jpg",[24,338,339,342,343,346,347],{},[15,340,341],{},"Step 7",": After test successfully, click \"",[15,344,345],{},"Next\""," to continue. ",[57,348],{"className":349,"alt":62,"src":350,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080709\u002FScreen-Shot-2020-02-20-at-10.50.56-AM.png",[93,352],{},[57,354],{"className":355,"alt":62,"src":356,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080755\u002FScreen-Shot-2020-02-20-at-10.54.15-AM.png",[24,358,359,360,363,364],{},"Click \"",[15,361,362],{},"Review","\" to publish your message. ",[57,365],{"className":366,"alt":62,"src":367,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080836\u002FScreen-Shot-2020-02-20-at-10.56.19-AM.png",[93,369],{},[57,371],{"className":372,"alt":62,"src":373,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080911\u002FScreen-Shot-2020-02-20-at-10.55.31-AM-1024x663.png",[24,375,376,377,380],{},"When click \"",[15,378,379],{},"Publish","\" message will send to the app.",[24,382,383],{},"Result:",[385,386,391,395],"div",{"className":387},[388,389,390],"flex","justify-center","gap-4",[57,392],{"className":393,"alt":62,"src":394,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080936\u002FScreenshot_20200219-173204-57-1-576x1024.jpg",[57,396],{"className":397,"alt":62,"src":398,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07080953\u002FScreenshot_20200219-173801-59-576x1024.jpg",[93,400],{},[57,402],{"className":403,"alt":62,"src":404,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081013\u002FScreenshot_20200219-173901-61-576x1024.jpg",[19,406,408],{"id":407},"iv-cloud-message","IV. Cloud Message",[185,410,188],{"id":411},"_1-introduction-1",[24,413,414],{},"Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.",[185,416,195],{"id":417},"_2-get-start-1",[24,419,420,200,422,127,424,427,428,210,430,55],{},[15,421,50],{},[15,423,203],{},[15,425,426],{},"‘com.google.firebase:firebase-messaging:20.1.0’"," \"into \"",[15,429,148],{},[15,431,213],{},[57,433],{"className":434,"alt":62,"src":435,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081040\u002FScreen-Shot-2020-02-20-at-8.07.39-AM-63-1024x627.png",[24,437,438,440],{},[15,439,69],{}," : Add filter to AndroidManifest file.",[225,442,445],{"className":443,"code":444,"language":230},[228],"\u003Cservice\n    android:name=\".java.MyFirebaseMessagingService\"\n    android:exported=\"false\">\n    \u003Cintent-filter>\n        \u003Caction android:name=\"com.google.firebase.MESSAGING_EVENT\" \u002F>\n    \u003C\u002Fintent-filter>\n\u003C\u002Fservice>\n",[232,446,444],{"__ignoreMap":62},[24,448,449,450,454],{},"MyFirebaseMessagingService is a service that extends ",[451,452,453],"em",{},"FirebaseMessagingService",". This is required when you want to do any message handling beyond receiving notifications on apps in the background. To receive notifications in foreground apps, to receive data payload, to send upstream messages, and so on, you must use this service.",[57,456],{"className":457,"alt":62,"src":458,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081111\u002FScreen-Shot-2020-02-20-at-8.13.02-AM-65-1024x625.png",[24,460,461,462,465,466,469],{},"Now you will see an error at ",[15,463,464],{},"line 23",". This is occurred because we don’t have ",[451,467,468],{},"MyFirebaseMessagingService"," file in project so let create it.",[57,471],{"className":472,"alt":62,"src":473,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081137\u002FScreen-Shot-2020-02-20-at-8.16.28-AM-67.png",[24,475,476,480],{},[57,477],{"className":478,"alt":62,"src":479,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081206\u002FScreen-Shot-2020-02-20-at-8.17.14-AM-69.png",[93,481],{},[57,483],{"className":484,"alt":62,"src":485,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081227\u002FScreen-Shot-2020-02-20-at-8.17.30-AM-71-1024x183.png",[24,487,488,489,492,493,499],{},"Change package name from ",[451,490,491],{},".java.MyFirebaseMessagingService"," to ",[451,494,495],{},[496,497,498],"package",{},".MyFirebaseMessagingService",".",[57,501],{"className":502,"alt":62,"src":503,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081251\u002FScreen-Shot-2020-02-20-at-8.24.31-AM-77-1024x627.png",[24,505,506,508],{},[15,507,79],{}," (optional): Set a default icon and color, you can skip this step if you do not want icon and color in your notification.",[225,510,513],{"className":511,"code":512,"language":230},[228],"\u003C!-- Set custom default icon. This is used when no icon is set for incoming notification messages.\n     See README(https:\u002F\u002Fgoo.gl\u002Fl4GJaQ) for more. -->\n\u003Cmeta-data\n    android:name=\"com.google.firebase.messaging.default_notification_icon\"\n    android:resource=\"@drawable\u002Fic_stat_ic_notification\" \u002F>\n\u003C!-- Set color used with incoming notification messages. This is used when no color is set for the incoming\n     notification message. See README(https:\u002F\u002Fgoo.gl\u002F6BKBk7) for more. -->\n\u003Cmeta-data\n    android:name=\"com.google.firebase.messaging.default_notification_color\"\n    android:resource=\"@color\u002FcolorAccent\" \u002F>\n",[232,514,512],{"__ignoreMap":62},[57,516],{"className":517,"alt":62,"src":518,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081324\u002FScreen-Shot-2020-02-20-at-8.36.41-AM-79-1024x627.png",[24,520,521,523,524,529,530,535,536,499],{},[15,522,103],{}," (Optional): From Android 8.0 (API level 26) and higher, ",[28,525,528],{"href":526,"rel":527},"https:\u002F\u002Fdeveloper.android.com\u002Fguide\u002Ftopics\u002Fui\u002Fnotifiers\u002Fnotifications.html#ManageChannels",[32],"notification channels"," are supported and recommended. FCM provides a default notification channel with basic settings. If you prefer to ",[28,531,534],{"href":532,"rel":533},"https:\u002F\u002Fdeveloper.android.com\u002Fguide\u002Ftopics\u002Fui\u002Fnotifiers\u002Fnotifications.html#CreateChannel",[32],"create"," and use your own default channel, set default_notification_channel_id to the ID of your notification channel object as shown; FCM will use this value whenever incoming messages do not explicitly set a notification channel. To learn more, see ",[28,537,539],{"href":526,"rel":538},[32],"Manage notification channels",[24,541,542,543,546],{},"Goto ",[15,544,545],{},"res\u002Fvalues\u002Fstrings.xml"," and add this line.",[225,548,551],{"className":549,"code":550,"language":230},[228],"\u003Cstring name=\"default_notification_channel_id\">1\u003C\u002Fstring>\n",[232,552,550],{"__ignoreMap":62},[57,554],{"className":555,"alt":62,"src":556,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081349\u002FScreen-Shot-2020-02-20-at-8.44.38-AM-83-1024x350.png",[24,558,559,560,563],{},"Open ",[15,561,562],{},"AndroidManifest"," file and add this code.",[225,565,568],{"className":566,"code":567,"language":230},[228],"\u003Cmeta-data\n    android:name=\"com.google.firebase.messaging.default_notification_channel_id\"\n    android:value=\"@string\u002Fdefault_notification_channel_id\" \u002F>\n",[232,569,567],{"__ignoreMap":62},[57,571],{"className":572,"alt":62,"src":573,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081416\u002FScreen-Shot-2020-02-20-at-8.46.55-AM-85-1024x627.png",[24,575,576,577,579,580,583],{}," ",[15,578,138],{},": Open ",[15,581,582],{},"MainActivity"," to retrieve the current registration token, add this function",[225,585,588],{"className":586,"code":587,"language":230},[228],"private fun createInstanceId() {\n    FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener { task ->\n        if (!task.isSuccessful) {\n            Log.w(TAG, \"getInstanceId failed\", task.exception)\n            return@addOnCompleteListener\n        }\n\n        \u002F\u002Fget id Token\n        \u002F\u002F Get new Instance ID token\n        val token = task.result?.token\n\n        \u002F\u002F Log and toast\n        Log.d(TAG, \"token: $token\")\n        Toast.makeText(baseContext, \"token: $token\", Toast.LENGTH_SHORT).show()\n    }\n}\n",[232,589,587],{"__ignoreMap":62},[57,591],{"className":592,"alt":62,"src":593,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081446\u002FScreen-Shot-2020-02-20-at-8.56.08-AM-87-1024x626.png",[24,595,596],{},"Run the app, to get Firebase instance ID.",[57,598],{"className":599,"alt":62,"src":600,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081508\u002FScreenshot_20200220-125154-768x1365.jpg",[24,602,603,605,606,608],{},[15,604,170],{},": Add the code below into the ",[15,607,468],{}," class.",[225,610,613],{"className":611,"code":612,"language":230},[228],"class MyFirebaseMessagingService : FirebaseMessagingService() {\n    companion object {\n        private val TAG = this::class.java.simpleName\n    }\n\n    override fun onNewToken(token: String) {\n        Log.d(TAG, \"Refreshed token: $token\")\n        super.onNewToken(token)\n    }\n\n    override fun onMessageReceived(remoteMessage: RemoteMessage) {\n        super.onMessageReceived(remoteMessage)\n        Log.d(TAG, \"From: ${remoteMessage.from}\")\n\n        remoteMessage.data.isNotEmpty().let {\n        }\n\n        remoteMessage.notification?.let {\n            Log.d(TAG, \"Message Notification Body: ${it.body}\")\n            it.body?.let { body ->\n                sendNotification(body)\n            }\n        }\n    }\n\n    private fun sendNotification(messageBody: String) {\n        val intent = Intent(this, CloudMessageActivity::class.java)\n        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP\n        val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)\n\n        val channelId = getString(R.string.default_notification_channel_id)\n        val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)\n        val notificationBuilder = NotificationCompat.Builder(this, channelId)\n            .setSmallIcon(R.drawable.ic_notifications)\n            .setContentTitle(\"Mess Title\")\n            .setContentText(messageBody)\n            .setAutoCancel(true)\n            .setSound(defaultSoundUri)\n            .setContentIntent(pendingIntent)\n\n        val notificationManager =\n            getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\n\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {\n            val channel = NotificationChannel(\n                channelId, \"Channel human readable title\",\n                NotificationManager.IMPORTANCE_DEFAULT\n            )\n            notificationManager.createNotificationChannel(channel)\n        }\n\n        notificationManager.notify(1, notificationBuilder.build())\n    }\n}\n",[232,614,612],{"__ignoreMap":62},[24,616,617,619,620,499],{},[15,618,341],{},": Test ",[15,621,622],{},"Cloud Messaging",[57,624],{"className":625,"alt":62,"src":626,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081528\u002FScreen-Shot-2020-02-20-at-12.47.45-PM.png",[24,628,629,630,576,633,636,637,639,640,643,644,649],{},"Enter ",[15,631,632],{},"Notification",[15,634,635],{},"Title",", ",[15,638,230],{}," and ",[15,641,642],{},"image"," (optional) ex: ",[28,645,648],{"href":646,"rel":647},"https:\u002F\u002Fcdn.pixabay.com\u002Fphoto\u002F2017\u002F07\u002F07\u002F02\u002F05\u002Fsymbol-2480161%5C_960%5C_720.png",[32],"https:\u002F\u002Fcdn.pixabay.com\u002Fphoto\u002F2017\u002F07\u002F07\u002F02\u002F05\u002Fsymbol-2480161\\_960\\_720.png"," and send test message.",[57,651],{"className":652,"alt":62,"src":653,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081545\u002FScreen-Shot-2020-02-20-at-1.00.12-PM.png",[24,655,656,657,660],{},"Add the token we got from ",[15,658,659],{},"Logcat"," (step 5)",[57,662],{"className":663,"alt":62,"src":664,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081608\u002FScreen-Shot-2020-02-20-at-1.07.28-PM.png",[24,666,667,669,670],{},[15,668,331],{},":\n",[57,671],{"className":672,"alt":62,"src":673,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081635\u002FScreenshot_20200220-141558-768x1365.jpg",[24,675,676,678],{},[15,677,341],{},": Create and send message.",[24,680,681,682,685,686,690],{},"After test successfully, click \"",[15,683,684],{},"Next","\" to continue.\n",[57,687],{"className":688,"alt":62,"src":689,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081717\u002FScreen-Shot-2020-02-20-at-2.22.42-PM.png",[93,691],{},[24,693,694,698],{},[57,695],{"className":696,"alt":62,"src":697,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081729\u002FScreen-Shot-2020-02-20-at-2.25.56-PM.png",[93,699],{},[57,701],{"className":702,"alt":62,"src":703,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081755\u002FScreen-Shot-2020-02-20-at-2.23.43-PM.png",[24,705,359,706,708],{},[15,707,379],{},"\" to send a message.",[24,710,711,332],{},[15,712,331],{},[385,714,716,721],{"className":715},[388,389,390],[57,717],{"className":718,"alt":62,"src":719,"style":720},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081831\u002FScreenshot_20200220-144456_One-UI-Home-768x652.jpg","width: 60%;",[57,722],{"className":723,"alt":62,"src":724,"style":725},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081852\u002FScreenshot_20200220-144505-768x954.png","width: 40%;",[93,727],{},[57,729],{"className":730,"alt":62,"src":731,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07081914\u002FScreenshot_20200220-144509-576x1024.jpg",[19,733,735],{"id":734},"v-realtime-database","V. Realtime Database",[185,737,188],{"id":738},"_1-introduction-2",[24,740,741],{},"The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data.",[185,743,195],{"id":744},"_2-get-start-2",[24,746,747,200,749,752,753,55],{},[15,748,50],{},[15,750,751],{},"implementation 'com.google.firebase:firebase-database:19.2.1'"," \"into \"build.gradle\" (app) and Click \"",[15,754,213],{},[57,756],{"className":757,"alt":62,"src":758,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082008\u002FScreen-Shot-2020-02-20-at-3.26.15-PM-1024x382.png",[24,760,761,763],{},[15,762,69],{},": Configure realtime database rules for testing",[57,765],{"className":766,"alt":62,"src":767,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082049\u002FScreen-Shot-2020-02-20-at-3.38.14-PM-1024x541.png",[24,769,770,771],{},"About real time database rules you can read from ",[28,772,775],{"href":773,"rel":774},"https:\u002F\u002Ffirebase.google.com\u002Fdocs\u002Fdatabase\u002Fsecurity\u002Fquickstart#sample-rules%22",[32],"here",[24,777,778,780],{},[15,779,79],{},": Create UserModel Class",[225,782,785],{"className":783,"code":784,"language":230},[228],"data class UserModel(\n    var id: String = \"\",\n    var name: String = \"\",\n    var age: Int = 0,\n    var email: String = \"\"\n) {\n    override fun toString(): String {\n        return \"UserModel(id='$id', name='$name', age=$age, email='$email')\"\n    }\n}\n",[232,786,784],{"__ignoreMap":62},[24,788,789,791],{},[15,790,103],{},": Create layout with 3 edit (name, age and email), 4 button (insert, get, update, delete), 1 recycler view to contain User data",[24,793,794,795],{},"This is my layout. ",[57,796],{"className":797,"alt":62,"src":798,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082107\u002FScreenshot_20200220-160304-739x1536.png",[24,800,801],{},[15,802,803],{},"Step 5:",[24,805,806],{},"Write to your database",[24,808,809,810,499],{},"First initialize ",[451,811,812],{},"databaseReference",[225,814,817],{"className":815,"code":816,"language":230},[228],"private fun initDatabase() {\n    databaseReference = FirebaseDatabase.getInstance().reference\n}\n",[232,818,816],{"__ignoreMap":62},[24,820,821],{},"Next, get data from EditText and insert to database.",[225,823,826],{"className":824,"code":825,"language":230},[228],"private fun insertUser() {\n    if (edt_name.text.isNullOrEmpty() || edt_age.text.isNullOrEmpty() || edt_email.text.isNullOrEmpty()) {\n        Toast.makeText(this, \"Some field are missing.\", Toast.LENGTH_SHORT).show()\n        return\n    }\n\n    \u002F\u002Fget key\n    val key = databaseReference.child(\"User\").push().key\n\n    \u002F\u002Fget user data from edit text\n    val user = UserModel(\n        name = edt_name.text.toString(),\n        age = edt_age.text.toString().toInt(),\n        email = edt_email.text.toString()\n    )\n\n    key?.let {\n        user.id = key\n\n        \u002F\u002F Write a data to the database\n        databaseReference.child(\"User\").child(key).setValue(user).addOnSuccessListener {\n            clearText()\n            \u002F\u002Fget user data from database\n            getUser()\n            \u002F\u002Fscroll to new item\n            recycler_user.scrollToPosition(recyclerAdapter.userList.size - 1)\n        }\n            .addOnFailureListener {\n                Toast.makeText(this, \"Upload Error\", Toast.LENGTH_SHORT).show()\n            }\n    }\n}\n",[232,827,825],{"__ignoreMap":62},[24,829,830],{},"Add this code to insert button click event.",[225,832,835],{"className":833,"code":834,"language":230},[228],"btn_insert.setOnClickListener {\n    insertUser()\n}\n",[232,836,834],{"__ignoreMap":62},[24,838,839,840,843],{},"After clicking the \"",[15,841,842],{},"Insert","\" button in your app, data will be send to Firebase immediately.",[57,845],{"className":846,"alt":62,"src":847,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082139\u002FScreen-Shot-2020-02-20-at-4.36.54-PM.png",[24,849,850],{},[15,851,852],{},"Read database:",[225,854,857],{"className":855,"code":856,"language":230},[228],"databaseReference.child(\"User\").addValueEventListener(object : ValueEventListener {\n    override fun onCancelled(dataError: DatabaseError) {\n        Toast.makeText(this@DataBaseActivity, \"Upload Error\", Toast.LENGTH_SHORT).show()\n    }\n\n    override fun onDataChange(dataSnapshot: DataSnapshot) {\n        \n        \u002F\u002Fget user list from database\n        val list = dataSnapshot.children.mapNotNull {\n            it.getValue(UserModel::class.java)\n        }\n        list.forEach {\n            Log.i(\"Users\", it.toString())\n        }\n        \u002F\u002Fadd to recycler view\n        if (list.isNotEmpty()) {\n            recyclerAdapter.userList.clear()\n            recyclerAdapter.userList.addAll(list)\n            recyclerAdapter.notifyDataSetChanged()\n        }\n    }\n})\n",[232,858,856],{"__ignoreMap":62},[57,860],{"className":861,"alt":62,"src":862,"style":126},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082214\u002FScreenshot_20200221-082417-739x1536.png",[24,864,865],{},[15,866,867],{},"Update database:",[225,869,872],{"className":870,"code":871,"language":230},[228],"private fun updateUser() {\n    user?.let {\n        \u002F\u002Fcreate new user object\n        val user = UserModel(\n            it.id,\n            edt_name.text.toString(),\n            edt_age.text.toString().toInt(),\n            edt_email.text.toString()\n        )\n        \u002F\u002Fupdate user\n        databaseReference.child(\"User\u002F${it.id}\").setValue(user)\n    }\n}\n",[232,873,871],{"__ignoreMap":62},[57,875],{"className":876,"alt":62,"src":877,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082239\u002FScreen-Shot-2020-02-20-at-5.13.21-PM.png",[24,879,880,332],{},[15,881,882],{},"Delete database",[225,884,887],{"className":885,"code":886,"language":230},[228],"private fun deleteUser() {\n    \u002F\u002F get user id\n    val query =\n        databaseReference.child(\"User\").orderByChild(\"id\").equalTo(user?.id)\n\n    query.addListenerForSingleValueEvent(object : ValueEventListener {\n        override fun onDataChange(dataSnapshot: DataSnapshot) {\n            for (user in dataSnapshot.children) {\n                \u002F\u002Fremove user\n                user.ref.removeValue().addOnSuccessListener {\n                    clearText()\n                }\n            }\n        }\n\n        override fun onCancelled(databaseError: DatabaseError) {\n            Log.e(\n                TAG,\n                \"onCancelled\",\n                databaseError.toException()\n            )\n        }\n    })\n    getUser()\n}\n",[232,888,886],{"__ignoreMap":62},[57,890],{"className":891,"alt":62,"src":892,"style":64},[60,61],"https:\u002F\u002Fs3-ap-southeast-1.amazonaws.com\u002Fhomepage-media\u002Fwp-content\u002Fuploads\u002F2020\u002F02\u002F07082302\u002FScreen-Shot-2020-02-20-at-5.14.08-PM.png",[19,894,896],{"id":895},"vi-reference-documents","VI. Reference documents",[24,898,899],{},[28,900,901],{"href":901,"rel":902},"https:\u002F\u002Ffirebase.google.com\u002Fdocs\u002Fguides",[32],[24,904,905],{},[28,906,907],{"href":907,"rel":908},"https:\u002F\u002Fgithub.com\u002Ffirebase\u002Fquickstart-android\u002Fblob\u002F995be41782f84b3c54e41d7d7e5d3a5048fe329e\u002Fmessaging\u002Fapp\u002Fsrc\u002Fmain\u002Fjava\u002Fcom\u002Fgoogle\u002Ffirebase\u002Fquickstart\u002Ffcm\u002Fkotlin\u002FMyFirebaseMessagingService.kt#L65-L77",[32],[24,910,911],{},[28,912,913],{"href":913,"rel":914},"https:\u002F\u002Fproandroiddev.com\u002Ffirebase-android-playground-realtime-database-560d4e18404a",[32],[24,916,917],{},[28,918,919],{"href":919,"rel":920},"https:\u002F\u002Fwww.learnhowtoprogram.com\u002Fandroid\u002Fdata-persistence\u002Ffirebase-reading-data-and-event-listeners",[32],{"title":62,"searchDepth":922,"depth":922,"links":923},2,[924,925,926,931,935,939],{"id":21,"depth":922,"text":22},{"id":37,"depth":922,"text":38},{"id":182,"depth":922,"text":183,"children":927},[928,930],{"id":187,"depth":929,"text":188},3,{"id":194,"depth":929,"text":195},{"id":407,"depth":922,"text":408,"children":932},[933,934],{"id":411,"depth":929,"text":188},{"id":417,"depth":929,"text":195},{"id":734,"depth":922,"text":735,"children":936},[937,938],{"id":738,"depth":929,"text":188},{"id":744,"depth":929,"text":195},{"id":895,"depth":922,"text":896},[941,942],"mobile","tech talk","Briswell Vietnam Co Ltd","2020-02-25","What is Firebase Google Firebase is a Google-backed application development software that enables developers to develop iOS, Android and Web apps. Firebase provides tools for tracking analytics, reporting and fixing app crashes, creating marketing and product experiment. Firebase has many services and today I’m going to introduce to in-app messaging, cloud messages and real-time databases","md",{},true,"\u002Fnews\u002Fandroid-firebase-for-beginer",null,{"title":5,"description":945},"news\u002Fandroid-firebase-for-beginer","https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2026\u002F06\u002F05080300\u002FFirebase.jpg","N4uwmumYVuOXXXDBvAUHIP2cTOi8KDDHR8AMiShIWh8",1782205030920]