Android Example Firebase Database working example

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
 

Attachments

  • Working Firebase Database example simple (no credentials).zip
    480.4 KB · Views: 1,923
Last edited:

softmicro

Member
Licensed User
Longtime 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
 

rbghongade

Active Member
Licensed User
Longtime 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.
 

beelze69

Active Member
Licensed User
Longtime User
Hi,

Hi !

I saw the example.. Sorry if I sound too basic.

When you say 'get from the database' are you meaning 'querying the database' .. If I were to query the database, can you tell me how to do the following :

1) Create the database and table in Firebase.
2) Ensure that anybody can log into the database
3) Logging into Firebase
4) Fire a query and display the output in say a webview control.

Thanks.
 
Last edited:

imam syaifuddin

Member
Licensed User
Longtime User
I get an error when compiling, what should I do?

B4A Version: 9.80
Java Version: 11
Parsing code. (0.07s)
Building folders structure. (0.14s)
Compiling code. (0.27s)
Compiling layouts code. (0.01s)
Organizing libraries. (0.00s)
(Android Support Library)
Generating R file. Error
C:\Users\drimamskom\AppData\Local\Android\sdk\tools\..\extras\b4a_local\unpacked-facebook-common-5.5.0-63703520598000\res\values\values.xml:71: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
C:\Users\drimamskom\AppData\Local\Android\sdk\tools\..\extras\b4a_local\unpacked-facebook-common-5.5.0-63703520598000\res\values\values.xml:76: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.
 
Top