Android Example Firebase Database working example

Discussion in 'Tutorials & Examples' started by pedrocam, Aug 22, 2017.

  1. pedrocam

    pedrocam Member Licensed User

    Hi,

    I decided to post this working example in the hopes that it can be useful to some people, and also maybe eventually someone will update it. I find database one of the most useful things in Firebase and maybe you do too. After getting frustrated with the almost working firebase realtime database, I put this patchwork together. Although it is not realtime, it does work normally. Anyways hope you like it.

    This example allows you to login with facebook, and google, and post and get from the database.

    This uses REST operations to post and put and get from the firebase db. You must be logged in to post. I know you can do anonymous login with authex, but it is not implemented here. I used @fredo s custom http and codes for the REST operations. THANKS FREDO!!

    Before using this, you must integrate firebase, and implement facebook and/or google login. You will need atleast one of the two login methods working. Google is easier.
    Firebase integration: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
    Google login: https://www.b4x.com/android/forum/threads/firebaseauth-authenticate-your-users.67875/
    Facebook integration: https://www.b4x.com/android/forum/threads/facebook-extends-firebaseauth-to-support-facebook.67954/

    If you want to put to the DB instead of posting, then just change the button command to put instead of post, and it works.

    One way to make it update similar to realtime is via notifications (ie. when a user posts something, he broadcasts notification too all users who then refresh their database), but notification is not implemented here.

    WhatsApp Image 2017-08-21 at 21.44.37.jpeg

    ****DONT DO THIS ON AN ACTIVE DB IF YOU DONT KNOW WHAT YOU ARE DOING. A PUT COMMAND CAN EASE ALL YOUR DATA. CREATE A NEW DB FOR YOURSELF, OR KNOW WHAT YOU ARE DOING***


    *******************************************************
    DOWNLOAD LINK:
    https://www.dropbox.com/s/a9mqvj1dcaigjjw/Working Firebase Database example simple.zip?dl=0
    The attached file in this thread does not work (b4x filesize limit I had to delete opt.jar and without it, it will not work). Please use the file in the link above.


    Tags: rest, curl, resftul, firebase
    Credit: Used code from @fredo example
     

    Attached Files:

    Last edited: Aug 22, 2017
    ocalle, Mashiane, trepdas and 7 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Thank you for sharing. Note that you should use File - Export as zip to create a zip with the required files.
     
    pedrocam likes this.
  3. trepdas

    trepdas Member Licensed User

    Thank you
     
    Last edited: Feb 23, 2018
  4. softmicro

    softmicro Member Licensed User

    I need this demo to work in order to be able to adapt it to an application that I have previously developed but that uses text messages (SMS). I add captures of my problems.

    Core Vers. 8.00
    Facebook Vers. 1.00
    FireAuth Ver.1.06
    JSON Vers. 1.10
    OkHttp Vers. 1.20
    StringUtils Vers.1.12

    Initial authentication test

    Sign out!
    onAuthStateChanged: com.google.firebase.auth.internal.zzj@3e62b2e3
    onAuthStateChanged: com.google.firebase.auth.internal.zzj@3e62b2e3
    SignInWithGoogle called
    Sign in with Google Clicked
    '** Activity (Main) Pause, UserClosed = False **
    sending message To waiting queue (OnActivityResult)
    running waiting messages (1)
    SignInWithGoogle.ResultArrived
    ResultArrived Error: Status {statusCode = unknown status code: 12500, resolution = Null}, Null
    ** Activity (Main) Resume **

    I need SHA1?
    Where?
    How?



    I enable FirebaseRealtimeDatabase
    Core Vers. 8.00
    Facebook Vers. 1.00
    FireAuth Ver.1.06
    FirebaseRealtimeDatabase Vers.2.53)
    JSON Vers. 1.10
    OkHttp Vers. 1.20
    StringUtils Vers.1.12

    Generating the file R. Error
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 114: error: Error retrieving parent For item: No resource found that matches the given name 'Theme.AppCompat.DayNight.DarkActionBar'.
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database simple example (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 117: error: Error: No resource found that matches the given name: attr colorAccent '.
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 115: error: Error: No resource found that matches the given name: attrimary color.
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 116: error: Error: No resource found that matches the given name: attrPrimaryDark '.
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 136: error: Error retrieving parent For item: No resource found that matches the given name '@ style / Widget.AppCompat.Button.Colored'.
    'C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 180: error: Error retrieving parent For item: No resource found that matches the given name 'Widget.AppCompat.Spinner.Underlined'.
    C: \ Users \ Alejandro \ Downloads \ Working Firebase Database example simple (no credentials) \ Objects \ bin \ extra \ res2 \ res \ values \ values.xml: 265: error: Error retrieving parent For item: No resource found that matches the given name 'Widget.Design.TextInputLayout'.

    Thanks you
     
  5. rbghongade

    rbghongade Active Member Licensed User

    Thanks for the example. Is there a way to retrieve all the logged values of the field using GET? I have a field called as "DATA" which is getting appended using an ESP8266. Now my requirement is to retrieve ALL the values.
     
  6. beelze69

    beelze69 Member Licensed User

     
    Last edited: Jan 1, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice