Android Question B4A and firebase database.

keirS

Well-Known Member
Licensed User
Longtime User
You can use a Firebase database now. There is a REST interface for it so you can use the okhttp library and okhttputils to access it.
 
Upvote 0

skyluke83

Member
Licensed User
Longtime User
Guys, I'd like to work on a Firebase Database library/wrapper. Do you have any tutorial on how to make a wrapper?
Thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

skyluke83

Member
Licensed User
Longtime User
DonManfred, you did a wrapper for Firebase, right? I'm writing the wrapper for the Realtime Database and I have a simple yet crucial question: FirebaseDatabase has a constructor who requires a FirebaseApp object. Who is going to pass it? 'Cause I don't think B4A will do it, when a new instance is Dimmed ;) Is it related in some way with the FirebaseInitProvider that is declared in the manifest?
 
Upvote 0

fredo

Well-Known Member
Licensed User
Longtime User
"...I'm writing the wrapper for the Realtime Database..."

I'm glad someone's taken the challange to make the Firebase Realtime Database available for the B4X community.

Since I work with Erel's Firebase Libs my productivity got a real boost regarding the cloud-related requirements of my apps. What's really missing right now is the JSON-Storage-Tree. I was trying to use a workaround with JSON files and Firebase Storage, but it lacks the needed functionality.

Do you have an estimation, when the Firebase Realtime Database Lib is ready to use?

If it's Donationware I will gladly provide the requested amount.
 
Last edited:
Upvote 0

fredo

Well-Known Member
Licensed User
Longtime User
You can use a Firebase database now. There is a REST interface for it so you can use the okhttp library and okhttputils to access it.

The possibility to use a REST API looks interesting.

I took a look through their guide at https://firebase.google.com/docs/database/rest/start and considering to give it a try.


I am wondering if you could provide a small B4A example just to get a grip on this.



Furthermore there is a "Helper Library" JAVA mentioned. 15-07-_2016_18-33-47.jpg Would it be possible to wrap this for B4X?
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Please someone help me understand firebase in B4A context?

From firebase page:

Once a user authenticates to your app, Firebase manages their session, ensuring that the user is remembered across browser or application restarts.

but how this works in B4A? How "set", "update" and "push" can be made only to authenticated users if no session here?

Thanks to everyone for clarifications.
 
Upvote 0

Richard Goh

Active Member
Licensed User
Longtime User
it is using the REST part of the Firebase Database. You already can do the same with okHTTP.
Hi DonManfred,
How can we use okHttp to achieve this? I have try using below code but no record added. Any advice?
Thanks in advance.

B4X:
Dim JSONList As List
    JSONList.Initialize

    Dim mData As Map
    mData.Initialize
    mData.Put("key1", "1")
    mData.Put("key2", "2")
    mData.Put("key3", "3")

   JSONList.add(mData)

    Dim JSONGenerator As JSONGenerator
   JSONGenerator.Initialize2(JSONList)
   
    Dim JSONstring As String
   JSONstring = JSONGenerator.ToString
  
    Dim J1 As HttpJob
   
    J1.Initialize("J1", Me)
    J1.Download2("https://my.firebaseio.com/Test" , Array As String(vid, JSONstring))
 
Upvote 0

fredo

Well-Known Member
Licensed User
Longtime User
@Richard Goh
I'm struggling with the same challange since a few days now and I think the huge advantage of the NoSql Firebase Database is worth the efforts.

As I mentioned in #10 above the latest Firebase documentation recomments to use this JAVA helper library.

Since @DonManfred says it is too old to wrap it for B4X I fear that we have to figure something out the old fashioned way with "Poststring" and "Download".
 
Upvote 0

Richard Goh

Active Member
Licensed User
Longtime User
Hi fredo,
Agreed. I am trying to use okHttp as per donmanfred mentioned. But still trying on it to find a correct syntax to run.
Will update the solution if I managed to connect to firebase. Hope someone is doing the wrapper for firebase database. Then we will have alternative for the functions.
Thanks a lots.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
In comparison with Auth and FCM it seems complicated. And I don't know why.

I just did a test to retrieve an object. Maybe this will help:


I've crated two objects via console in the database (it seems that you can define anything here)

fire1.JPG


Rules changed to "everyone can read/write without permission"

fire3.JPG


In the browser I just typed (which is equal to httputils):

fire2.JPG


Result is: 55 :)

With just ".json" you'll get all the data :)

fire4.JPG
 
Upvote 0

Richard Goh

Active Member
Licensed User
Longtime User
Hi. At last, I am able to insert record by using below code to write the record. This is without using any authentication rules for database. We can use POST method but firebase will generate a special id for record added by POST method. Hope this will to save sometime and give some hint for those who are looking to use REST.

B4X:
    Dim mData As Map
    mData.Initialize
    mData.Put("FirstName", "First name")
    mData.Put("SecondName", "Second name")
    mData.Put("LastName", "Last name")

    Dim JSONGenerator As JSONGenerator
   JSONGenerator.Initialize(mData)
   
    Dim JSONstring As String
   JSONstring = JSONGenerator.ToPrettyString(0)
   
    Dim req As HttpRequest
    req.InitializePut2("https://xxxxxx.firebaseio.com/Name.json" , JSONstring.GetBytes("UTF8"))
    req.SetContentType("application/json")
   
    Dim exec As HttpClient
    exec.Initialize("b")
    exec.Execute(req, "1")
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0
Top