Does real-time database still work after the current Firebase library updates?
I get this error while adding the library-
I get this error while adding the library-
Honestly; i dont know as you are using an Old Version of the Library.Does real-time database still work after the current Firebase library updates?
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
FirebaseAuth initialized
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzj@120f846f
ref_onChildAdded(-LDpwoP_FCRq9g-4_qZR,null)
chat_onChildAdded(-LDpwoP_FCRq9g-4_qZR,users/b787bae78e11a83/Messages)
(MyMap) {time=1527766009510, From=ErelClone, Message=Hi Master, Title=MyGreatSubject}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
lib1:Raising.. customers_ondatachange()
(MyMap) {home_phone=NULL, address=123 9th Street, job_title=NewJobtitle, last_name=Mortensen, city=Salt Lake City, web_page=NULL, company=Company I, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=UT, id=9, [email protected], notes=NULL, country_region=USA, first_name=Sven}
customers_onChildAdded(7,customers/, SizeofCustomers: 1)
(MyMap) {home_phone=NULL, address=123 10th Street, job_title=Purchasing Manager, last_name=Wacker, city=Chicago, web_page=NULL, company=Company J, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=IL, id=10, email_address=NULL, notes=NULL, country_region=USA, first_name=Roland}
customers_onChildAdded(8,customers/, SizeofCustomers: 2)
(MyMap) {home_phone=NULL, address=123 11th Street, job_title=Purchasing Manager, last_name=Krschne, city=Miami, web_page=NULL, company=Company K, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=FL, id=11, email_address=NULL, notes=NULL, country_region=USA, first_name=Peter}
customers_onChildAdded(9,customers/, SizeofCustomers: 3)
(MyMap) {home_phone=NULL, address=123 12th Street, job_title=Purchasing Manager, last_name=Edwards, city=Las Vegas, web_page=NULL, company=Company L, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=NV, id=12, email_address=NULL, notes=NULL, country_region=USA, first_name=John}
customers_onChildAdded(10,customers/, SizeofCustomers: 4)
(MyMap) {home_phone=NULL, address=456 13th Street, job_title=Purchasing Representative, last_name=Ludick, city=Memphis, web_page=NULL, company=Company M, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=TN, id=13, email_address=NULL, notes=NULL, country_region=USA, first_name=Andre}
customers_onChildAdded(11,customers/, SizeofCustomers: 5)
(MyMap) {home_phone=NULL, address=456 14th Street, job_title=Purchasing Representative, last_name=Grilo, city=Denver, web_page=NULL, company=Company N, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=CO, id=14, email_address=NULL, notes=NULL, country_region=USA, first_name=Carlos}
customers_onChildAdded(12,customers/, SizeofCustomers: 6)
(MyMap) {home_phone=NULL, address=456 15th Street, job_title=Purchasing Manager, last_name=Kupkova, city=Honolulu, web_page=NULL, company=Company O, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=HI, id=15, email_address=NULL, notes=NULL, country_region=USA, first_name=Helena}
customers_onChildAdded(13,customers/, SizeofCustomers: 7)
(MyMap) {home_phone=NULL, address=456 16th Street, job_title=Purchasing Representative, last_name=Goldschmidt, city=San Francisco, web_page=NULL, company=Company P, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=CA, id=16, email_address=NULL, notes=NULL, country_region=USA, first_name=Daniel}
customers_onChildAdded(14,customers/, SizeofCustomers: 8)
(MyMap) {home_phone=NULL, address=456 17th Street, job_title=Owner, last_name=Bagel, city=Seattle, web_page=NULL, company=Company Q, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=WA, id=17, email_address=NULL, notes=NULL, country_region=USA, first_name=Jean Philippe}
customers_onChildAdded(15,customers/, SizeofCustomers: 9)
(MyMap) {home_phone=NULL, address=456 18th Street, job_title=Purchasing Representative, last_name=Autier Miconi, city=Boston, web_page=NULL, company=Company R, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=MA, id=18, email_address=NULL, notes=NULL, country_region=USA, first_name=Catherine}
customers_onChildAdded(16,customers/, SizeofCustomers: 10)
(MyMap) {home_phone=NULL, address=789 19th Street, job_title=Accounting Assistant, last_name=Eggerer, city=Los Angelas, web_page=NULL, company=Company S, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=CA, id=1, email_address=NULL, notes=NULL, country_region=USA, first_name=Alexander}
customers_onChildAdded(17,customers/, SizeofCustomers: 11)
(MyMap) {home_phone=NULL, address=789 20th Street, job_title=Purchasing Manager, last_name=Li, city=New York, web_page=NULL, company=Company T, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=NY, id=20, email_address=NULL, notes=NULL, country_region=USA, first_name=George}
customers_onChildAdded(18,customers/, SizeofCustomers: 12)
(MyMap) {home_phone=NULL, address=789 21th Street, job_title=Accounting Manager, last_name=Tham, city=Minneapolis, web_page=NULL, company=Company U, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=MN, id=21, email_address=NULL, notes=NULL, country_region=USA, first_name=Bernard}
customers_onChildAdded(19,customers/, SizeofCustomers: 13)
(MyMap) {home_phone=NULL, address=789 22th Street, job_title=Purchasing Assistant, last_name=Ramos, city=Milwaukee, web_page=NULL, company=Company V, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=WI, id=22, email_address=NULL, notes=NULL, country_region=USA, first_name=Luciana}
customers_onChildAdded(20,customers/, SizeofCustomers: 14)
(MyMap) {home_phone=NULL, address=789 23th Street, job_title=Purchasing Manager, last_name=Entin, city=Portland, web_page=NULL, company=Company W, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=OR, id=23, email_address=NULL, notes=NULL, country_region=USA, first_name=Michael}
customers_onChildAdded(21,customers/, SizeofCustomers: 15)
(MyMap) {home_phone=NULL, address=789 24th Street, job_title=Owner, last_name=Hasselberg, city=Salt Lake City, web_page=NULL, company=Company X, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=UT, id=24, email_address=NULL, notes=NULL, country_region=USA, first_name=Jonas}
customers_onChildAdded(22,customers/, SizeofCustomers: 16)
(MyMap) {home_phone=NULL, address=789 25th Street, job_title=Purchasing Manager, last_name=Rodman, city=Chicago, web_page=NULL, company=Company Y, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=IL, id=25, email_address=NULL, notes=NULL, country_region=USA, first_name=John}
customers_onChildAdded(23,customers/, SizeofCustomers: 17)
(MyMap) {home_phone=NULL, address=789 26th Street, job_title=Accounting Assistant, last_name=Liu, city=Miami, web_page=NULL, company=Company Z, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=FL, id=26, email_address=NULL, notes=NULL, country_region=USA, first_name=Run}
customers_onChildAdded(24,customers/, SizeofCustomers: 18)
(MyMap) {home_phone=NULL, address=789 27th Street, job_title=Purchasing Manager, last_name=Toh, city=Las Vegas, web_page=NULL, company=Company AA, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=NV, id=27, email_address=NULL, notes=NULL, country_region=USA, first_name=Karen}
customers_onChildAdded(25,customers/, SizeofCustomers: 19)
(MyMap) {home_phone=NULL, address=789 28th Street, job_title=Purchasing Manager, last_name=Raghav, city=Memphis, web_page=NULL, company=Company BB, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=TN, id=28, email_address=NULL, notes=NULL, country_region=USA, first_name=Amritansh}
customers_onChildAdded(26,customers/, SizeofCustomers: 20)
(MyMap) {home_phone=NULL, address=789 29th Street, job_title=Purchasing Manager, last_name=Lee, city=Denver, web_page=NULL, company=Company CC, fax_number=(123)555-0101, business_phone=(123)555-0100, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=CO, id=29, email_address=NULL, notes=NULL, country_region=USA, first_name=Soo Jung}
customers_onChildAdded(27,customers/, SizeofCustomers: 21)
customers_onDatachange(customers/)
customerListSize: 21
lib1:Raising.. chat_ondatachange()
chat_onDatachange(users/b787bae78e11a83/Messages)
Value type Map: anywheresoftware.b4a.objects.collections.Map$MyMap
Value = {-LDpwoP_FCRq9g-4_qZR={time=1527766009510, From=ErelClone, Message=Hi Master, Title=MyGreatSubject}}
'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
'************ Google Play Services Base (end) ************
'************ Firebase Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
'************ Firebase Base (end) ************
'************ Firebase Notifications ************
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
'************ Firebase Notifications (end)************
'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ Firebase Auth (end) ************
SetApplicationAttribute(android:theme, "@style/Theme.AppCompat")
AddPermission(android.permission.INTERNET) ' Allows applications to open network sockets.
AddPermission(android.permission.ACCESS_NETWORK_STATE) ' Allows applications to access information about networks.
Thank you very much! Let me test and come back to you.Manifest (B4A 8+)
B4X:'************ Google Play Services Base ************ CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase) '************ Google Play Services Base (end) ************ '************ Firebase Base ************ CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase) '************ Firebase Base (end) ************ '************ Firebase Notifications ************ CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications) '************ Firebase Notifications (end)************ '************ Firebase Auth ************ CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth) '************ Firebase Auth (end) ************ SetApplicationAttribute(android:theme, "@style/Theme.AppCompat") AddPermission(android.permission.INTERNET) ' Allows applications to open network sockets. AddPermission(android.permission.ACCESS_NETWORK_STATE) ' Allows applications to access information about networks.
You also need to download json databind from
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.8.9
Download the bundle and use the contained jar
All other needed files are in the attached firelayout.zip
Good luck
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim realtime As FirebaseDatabase
Dim myref As DatabaseReference
Dim cust As DatabaseReference
Dim msgref As DatabaseReference
Dim mymessages As DatabaseReference
Private lblName As Label
Private btnSignIn As Button
Private btnSignOut As Button
Private fbdb As Map
Private custmap As Map
'Private FireLayout1 As FireLayout
Private lv As ListView
Private btnGoogle As Button
Private btnEmail As Button
Private btnAnon As Button
Private btnLogout As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout2")
custmap.Initialize
realtime.Initialize("Realtime")
auth.Initialize("Auth")
If FirstTime Then
realtime.PersistenceEnabled = True
End If
realtime.goOnline
'FireLayout1.init("Layouts/B4A/fire2")
'myref.Initialize("Reference",realtime.getReferencefromUrl("https://xxxxxxxxx.firebaseio.com/"))
myref.Initialize("Reference",realtime.getReference2(""),"root")
'Log(myref.Key)
'Log(myref)
myref.addChildEventListener
myref.addListenerForSingleValueEvent
'myref.addValueEventListener
myref.keepSynced(True)
cust.Initialize("Customers",realtime.getReference2("customers/"),"customers/")
cust.LimitToFirst(5).orderByChild("id")
cust.addChildEventListener
cust.addValueEventListener
'cust.addListenerForSingleValueEvent
mymessages.Initialize("Chat",realtime.getReference2("users/"&Starter.phone.GetSettings("android_id")&"/Messages"),"users/"&Starter.phone.GetSettings("android_id")&"/Messages")
' Get the first 5 items order by Child "id" and add Listener
mymessages.LimitToFirst(5).orderByChild("From").startAt("Erel","From")
mymessages.addChildEventListener
mymessages.addValueEventListener
'mymessages.addListenerForSingleValueEvent
msgref.Initialize("Reference",myref.Child("users/"&Starter.phone.GetSettings("android_id")&"/Messages"),"users/"&Starter.phone.GetSettings("android_id")&"/Messages")
msgref.LimitToFirst(10).orderByChild("job_title").addChildEventListener
'msgref.addListenerForSingleValueEvent
'msgref.addChildEventListener
'msgref.addValueEventListener
Dim users() As String
users = Array As String("Someone", "ErelClone", "AnotherUser")
Dim rnduser As Int = Rnd(0,users.Length)
Dim msgs() As String
msgs = Array As String("Hello there", "Hi Master", "You are great")
Dim rndmsg As Int = Rnd(0,msgs.Length)
Dim tit() As String
tit = Array As String("My subject", "this is the subject", "MyGreatSubject")
Dim rndtit As Int = Rnd(0,tit.Length)
msgref.push.setValue(CreateMap("From":users(rnduser),"Title":tit(rndtit),"Message":msgs(rndmsg),"time":DateTime.Now),"MSG","Reference")
msgref.orderByKey
If auth.CurrentUser.IsInitialized Then
Auth_SignedIn(auth.CurrentUser)
Else
'auth.SignInWithGoogle
End If
End Sub
Sub Activity_Resume
'Log("Auth.currentUser = "&auth.CurrentUser)
If auth.CurrentUser.IsInitialized Then
Log("Auth.currentUser = "&auth.CurrentUser)
'Auth_SignedIn(auth.CurrentUser)
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSignIn_Click
auth.SignInWithGoogle
End Sub
Sub btnSignOut_Click
auth.SignOutFromGoogle
lblName.Text = "Goodbye!"
End Sub
Sub Auth_SignedIn (User As FirebaseUser)
Log("SignedIn: " & User.DisplayName)
lblName.Text = "Hello: " & User.DisplayName
myref.Initialize("Reference",realtime.Reference.Child("users/"&User.Uid&"/"),"/users/"&User.Uid&"/")
msgref.Initialize("Reference",realtime.getReference2("users/"&User.Uid&"/Messages/"),"users/"&User.Uid&"/Messages/")
Log(msgref.Key)
Log(msgref.Child("Messages"))
End Sub
Sub Fire_onFireLayoutChildClicked(view As Object)
'Log($"Fire_onFireLayoutChildClicked(${view}})"$)
If view Is Label Then
Dim lbl As Label = view
Log(lbl.Text)
End If
End Sub
Sub Fire_onFireLayoutChildLongClicked(view As Object)
'Log($"Fire_onFireLayoutChildLongClicked(${view})"$)
End Sub
Sub Reference_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object)
'Log($"ref_onCancelled(${errnum},${error},${tag})"$)
End Sub
Sub Reference_onChildAdded(snapshot As Object, child As String, tag As Object)
Log($"ref_onChildAdded(${child},${tag})"$)
Dim snap As DataSnapshot = snapshot
Select child
Case "options"
'Dim options As Map = snap.Value
'Log("-------------------")
'Log("--- OPTIONS -------")
'Log(options)
'Log("-------------------")
Case "geoFire"
Case "users"
'Dim users As Map = snap.Value
'Log("-------------------")
'Log("--- USERS ---------")
'Log(users)
'Log("-------------------")
End Select
'Log("-------------------")
'Log(snap.Key)
'Log(snap.Value)
'Log("---_onChildAdded()")
End Sub
Sub Reference_onChildChanged(snapshot As Object, child As String, tag As Object)
'Log($"ref_onChildchanged(${child},${tag})"$)
End Sub
Sub Reference_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object)
'Log($"ref_onComplete(${resultCode},${resultMessage},${tag})"$)
End Sub
Sub Reference_onChildMoved(snapshot As Object, child As String, tag As Object)
'Log($"ref_onChildMoved(${child},${tag})"$)
End Sub
Sub Reference_onChildRemoved(snapshot As Object, tag As Object)
'Log($"ref_onChildRemoved(${tag})"$)
End Sub
Sub Reference_onDataChange(snapshot As Object, tag As Object)
Log($"ref_onDatachange(${tag})"$)
If snapshot <> Null Then
Dim snap As DataSnapshot = snapshot
If snap.IsInitialized Then
'Log("Snapshot value is NOT null. Ok. Need to check content")
If snap.Value Is Map Then
'Log("Value type Map: "& GetType(snap.Value))
Dim m As Map = snap.Value
Log(m)
For Each k As String In m.Keys
Log(m.Get(k))
Next
'fbdb = snap.Value
'Log("FBDBroot set...")
else if snap.Value Is List Then
'Log("Value type List: "& GetType(snap.Value))
Dim customers As List = snap.Value
Log("referenceListSize: "&customers.Size)
else if snap.Value Is String Then
'Log("Value type String: "& GetType(snap.Value))
Dim val As String = snap.Value
Log("Value="&val)
Else
Log("Value type unknown: "& GetType(snap.Value))
End If
'users/b0d0d7f9b81140c3/)
'Dim json As JSONParser
'json.Initialize(snap.Value)
'Dim root As Map = json.NextObject
'Log(json.NextObject)
Else
Log("Snapshot not initialized")
End If
Else
Log("Snapshot is null")
End If
'Dim keys As List = snap.Children
'Log(keys.Size)
'Log(snap.Children)
End Sub
Sub chat_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object)
'Log($"chat_onCancelled(${errnum},${error},${tag})"$)
End Sub
Sub chat_onChildAdded(snapshot As Object, child As String, tag As Object)
Log($"chat_onChildAdded(${child},${tag})"$)
Dim snap As DataSnapshot = snapshot
Dim NewMessage As Map = snap.Value
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
Log(NewMessage)
'(MyMap) {time=1500126681816, From=Someone, Message=bla bla bla bla :-), Title=Hello world!}
Dim dt As Long = NewMessage.Get("time")
lv.AddTwoLines2("From "&NewMessage.Get("From")&": "&NewMessage.Get("Title"), DateTime.Date(dt)&": "&NewMessage.Get("Message"),NewMessage)
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("---_onChildAdded()")
End Sub
Sub chat_onChildChanged(snapshot As Object, child As String, tag As Object)
'Log($"chat_onChildchanged(${child},${tag})"$)
End Sub
Sub chat_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object)
'Log($"chat_onComplete(${resultCode},${resultMessage},${tag})"$)
End Sub
Sub chat_onChildMoved(snapshot As Object, child As String, tag As Object)
'Log($"chat_onChildMoved(${child},${tag})"$)
End Sub
Sub chat_onChildRemoved(snapshot As Object, tag As Object)
'Log($"chat_onChildRemoved(${tag})"$)
End Sub
Sub chat_onDataChange(snapshot As Object, tag As Object)
Log($"chat_onDatachange(${tag})"$)
If snapshot <> Null Then
Dim snap As DataSnapshot = snapshot
If snap.IsInitialized Then
If snap.Value <> Null And snap.Value <> "null" Then
'Log("Snapshot value is NOT null. Ok. Need to check content")
If snap.Value Is Map Then
Log("Value type Map: "& GetType(snap.Value))
'fbdb = snap.Value
Log("Value = "&snap.Value)
else if snap.Value Is List Then
'Log("Value type List: "& GetType(snap.Value))
Dim customers As List = snap.Value
Log("chatListSize: "&customers.Size)
else if snap.Value Is String Then
'Log("Value type String: "& GetType(snap.Value))
Dim val As String = snap.Value
Log("Value="&val)
Else
Log("Value type unknown: "& GetType(snap.Value))
End If
'users/b0d0d7f9b81140c3/)
'Dim json As JSONParser
'json.Initialize(snap.Value)
'Dim root As Map = json.NextObject
'Log(json.NextObject)
Else
'Log("Snapshot value is null")
'Dim m As Map
'm.Initialize
'myref.Value = CreateMap("Username":"DonManfred","Age":49)
End If
Else
Log("Snapshot not initialized")
End If
Else
Log("Snapshot is null")
End If
'Dim keys As List = snap.Children
'Log(keys.Size)
'Log(snap.Children)
End Sub
Sub customers_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object)
Log($"customers_onCancelled(${errnum},${error},${tag})"$)
End Sub
Sub customers_onChildAdded(snapshot As Object, child As String, tag As Object)
Dim snap As DataSnapshot = snapshot
Dim NewMessage As Map = snap.Value
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
Log(NewMessage)
custmap.Put(child,NewMessage)
Log($"customers_onChildAdded(${child},${tag}, SizeofCustomers: ${custmap.Size})"$)
'(MyMap) {address=789 28th Street, home_phone=NULL, job_title=Purchasing Manager, last_name=Raghav, city=Memphis, web_page=NULL, company=Company BB, business_phone=(123)555-0100, fax_number=(123)555-0101, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=TN, id=28, email_address=NULL, notes=NULL, country_region=USA, first_name=Amritansh}
'Dim dt As Long = NewMessage.Get("time")
lv.AddTwoLines("From: "&NewMessage.Get("first_name")&" "&NewMessage.Get("last_name"),"(ID "&NewMessage.Get("id")&") "&NewMessage.Get("address"))
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("========= NEW MSG =============")
'Log("---_onChildAdded()")
End Sub
Sub customers_onChildChanged(snapshot As Object, child As String, tag As Object)
Log($"customers_onChildchanged(${child},${tag})"$)
Dim snap As DataSnapshot = snapshot
Dim NewMessage As Map = snap.Value
'Log("========= CHANGED =============")
'Log("========= CHANGED =============")
'Log("========= CHANGED =============")
'Log(NewMessage)
custmap.Put(child,NewMessage)
End Sub
Sub customers_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object)
Log($"customers_onComplete(${resultCode},${resultMessage},${tag})"$)
End Sub
Sub customers_onChildMoved(snapshot As Object, child As String, tag As Object)
Log($"customers_onChildMoved(${child},${tag})"$)
Dim snap As DataSnapshot = snapshot
Dim NewMessage As Map = snap.Value
'Log("========= MOVED =============")
'Log("========= MOVED =============")
'Log("========= MOVED =============")
'Log(NewMessage)
custmap.Put(child,NewMessage)
End Sub
Sub customers_onChildRemoved(snapshot As Object, tag As Object)
Log($"customers_onChildRemoved(${tag})"$)
Dim snap As DataSnapshot = snapshot
Dim NewMessage As Map = snap.Value
'Log("========= REMOVED =============")
'Log("========= REMOVED =============")
'Log("========= REMOVED =============")
Log(NewMessage)
End Sub
Sub customers_onDataChange(snapshot As Object, tag As Object)
Log($"customers_onDatachange(${tag})"$)
If snapshot <> Null Then
Dim snap As DataSnapshot = snapshot
If snap.IsInitialized Then
If snap.Value <> Null And snap.Value <> "null" Then
'Log("Snapshot value is NOT null. Ok. Need to check content")
If snap.Value Is Map Then
'Log("Value type Map: "& GetType(snap.Value))
fbdb = snap.Value
'Log("FBDBroot set...")
else if snap.Value Is List Then
'Log("Value type List: "& GetType(snap.Value))
Dim customers As List = snap.Value
Log("customerListSize: "&customers.Size)
else if snap.Value Is String Then
'Log("Value type String: "& GetType(snap.Value))
Dim val As String = snap.Value
Log("Value="&val)
Else
Log("Value type unknown: "& GetType(snap.Value))
End If
'users/b0d0d7f9b81140c3/)
'Dim json As JSONParser
'json.Initialize(snap.Value)
'Dim root As Map = json.NextObject
'Log(json.NextObject)
Else
Log("Snapshot value is null")
'Dim m As Map
'm.Initialize
'myref.Value = CreateMap("Username":"DonManfred","Age":49)
End If
Else
Log("Snapshot not initialized")
End If
Else
Log("Snapshot is null")
End If
'Dim keys As List = snap.Children
'Log(keys.Size)
'Log(snap.Children)
End Sub
Can you send the project zip?This is the (CHAOTIC!!) code from my testapp.
But it may be a help a bit (i hope )
B4X:Sub Globals 'These global variables will be redeclared each time the activity is created. 'These variables can only be accessed from this module. Dim realtime As FirebaseDatabase Dim myref As DatabaseReference Dim cust As DatabaseReference Dim msgref As DatabaseReference Dim mymessages As DatabaseReference Private lblName As Label Private btnSignIn As Button Private btnSignOut As Button Private fbdb As Map Private custmap As Map 'Private FireLayout1 As FireLayout Private lv As ListView Private btnGoogle As Button Private btnEmail As Button Private btnAnon As Button Private btnLogout As Button End Sub Sub Activity_Create(FirstTime As Boolean) 'Do not forget to load the layout file created with the visual designer. For example: Activity.LoadLayout("Layout2") custmap.Initialize realtime.Initialize("Realtime") auth.Initialize("Auth") If FirstTime Then realtime.PersistenceEnabled = True End If realtime.goOnline 'FireLayout1.init("Layouts/B4A/fire2") 'myref.Initialize("Reference",realtime.getReferencefromUrl("https://xxxxxxxxx.firebaseio.com/")) myref.Initialize("Reference",realtime.getReference2(""),"root") 'Log(myref.Key) 'Log(myref) myref.addChildEventListener myref.addListenerForSingleValueEvent 'myref.addValueEventListener myref.keepSynced(True) cust.Initialize("Customers",realtime.getReference2("customers/"),"customers/") cust.LimitToFirst(5).orderByChild("id") cust.addChildEventListener cust.addValueEventListener 'cust.addListenerForSingleValueEvent mymessages.Initialize("Chat",realtime.getReference2("users/"&Starter.phone.GetSettings("android_id")&"/Messages"),"users/"&Starter.phone.GetSettings("android_id")&"/Messages") ' Get the first 5 items order by Child "id" and add Listener mymessages.LimitToFirst(5).orderByChild("From").startAt("Erel","From") mymessages.addChildEventListener mymessages.addValueEventListener 'mymessages.addListenerForSingleValueEvent msgref.Initialize("Reference",myref.Child("users/"&Starter.phone.GetSettings("android_id")&"/Messages"),"users/"&Starter.phone.GetSettings("android_id")&"/Messages") msgref.LimitToFirst(10).orderByChild("job_title").addChildEventListener 'msgref.addListenerForSingleValueEvent 'msgref.addChildEventListener 'msgref.addValueEventListener Dim users() As String users = Array As String("Someone", "ErelClone", "AnotherUser") Dim rnduser As Int = Rnd(0,users.Length) Dim msgs() As String msgs = Array As String("Hello there", "Hi Master", "You are great") Dim rndmsg As Int = Rnd(0,msgs.Length) Dim tit() As String tit = Array As String("My subject", "this is the subject", "MyGreatSubject") Dim rndtit As Int = Rnd(0,tit.Length) msgref.push.setValue(CreateMap("From":users(rnduser),"Title":tit(rndtit),"Message":msgs(rndmsg),"time":DateTime.Now),"MSG","Reference") msgref.orderByKey If auth.CurrentUser.IsInitialized Then Auth_SignedIn(auth.CurrentUser) Else 'auth.SignInWithGoogle End If End Sub Sub Activity_Resume 'Log("Auth.currentUser = "&auth.CurrentUser) If auth.CurrentUser.IsInitialized Then Log("Auth.currentUser = "&auth.CurrentUser) 'Auth_SignedIn(auth.CurrentUser) End If End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub Sub btnSignIn_Click auth.SignInWithGoogle End Sub Sub btnSignOut_Click auth.SignOutFromGoogle lblName.Text = "Goodbye!" End Sub Sub Auth_SignedIn (User As FirebaseUser) Log("SignedIn: " & User.DisplayName) lblName.Text = "Hello: " & User.DisplayName myref.Initialize("Reference",realtime.Reference.Child("users/"&User.Uid&"/"),"/users/"&User.Uid&"/") msgref.Initialize("Reference",realtime.getReference2("users/"&User.Uid&"/Messages/"),"users/"&User.Uid&"/Messages/") Log(msgref.Key) Log(msgref.Child("Messages")) End Sub Sub Fire_onFireLayoutChildClicked(view As Object) 'Log($"Fire_onFireLayoutChildClicked(${view}})"$) If view Is Label Then Dim lbl As Label = view Log(lbl.Text) End If End Sub Sub Fire_onFireLayoutChildLongClicked(view As Object) 'Log($"Fire_onFireLayoutChildLongClicked(${view})"$) End Sub Sub Reference_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object) 'Log($"ref_onCancelled(${errnum},${error},${tag})"$) End Sub Sub Reference_onChildAdded(snapshot As Object, child As String, tag As Object) Log($"ref_onChildAdded(${child},${tag})"$) Dim snap As DataSnapshot = snapshot Select child Case "options" 'Dim options As Map = snap.Value 'Log("-------------------") 'Log("--- OPTIONS -------") 'Log(options) 'Log("-------------------") Case "geoFire" Case "users" 'Dim users As Map = snap.Value 'Log("-------------------") 'Log("--- USERS ---------") 'Log(users) 'Log("-------------------") End Select 'Log("-------------------") 'Log(snap.Key) 'Log(snap.Value) 'Log("---_onChildAdded()") End Sub Sub Reference_onChildChanged(snapshot As Object, child As String, tag As Object) 'Log($"ref_onChildchanged(${child},${tag})"$) End Sub Sub Reference_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object) 'Log($"ref_onComplete(${resultCode},${resultMessage},${tag})"$) End Sub Sub Reference_onChildMoved(snapshot As Object, child As String, tag As Object) 'Log($"ref_onChildMoved(${child},${tag})"$) End Sub Sub Reference_onChildRemoved(snapshot As Object, tag As Object) 'Log($"ref_onChildRemoved(${tag})"$) End Sub Sub Reference_onDataChange(snapshot As Object, tag As Object) Log($"ref_onDatachange(${tag})"$) If snapshot <> Null Then Dim snap As DataSnapshot = snapshot If snap.IsInitialized Then 'Log("Snapshot value is NOT null. Ok. Need to check content") If snap.Value Is Map Then 'Log("Value type Map: "& GetType(snap.Value)) Dim m As Map = snap.Value Log(m) For Each k As String In m.Keys Log(m.Get(k)) Next 'fbdb = snap.Value 'Log("FBDBroot set...") else if snap.Value Is List Then 'Log("Value type List: "& GetType(snap.Value)) Dim customers As List = snap.Value Log("referenceListSize: "&customers.Size) else if snap.Value Is String Then 'Log("Value type String: "& GetType(snap.Value)) Dim val As String = snap.Value Log("Value="&val) Else Log("Value type unknown: "& GetType(snap.Value)) End If 'users/b0d0d7f9b81140c3/) 'Dim json As JSONParser 'json.Initialize(snap.Value) 'Dim root As Map = json.NextObject 'Log(json.NextObject) Else Log("Snapshot not initialized") End If Else Log("Snapshot is null") End If 'Dim keys As List = snap.Children 'Log(keys.Size) 'Log(snap.Children) End Sub Sub chat_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object) 'Log($"chat_onCancelled(${errnum},${error},${tag})"$) End Sub Sub chat_onChildAdded(snapshot As Object, child As String, tag As Object) Log($"chat_onChildAdded(${child},${tag})"$) Dim snap As DataSnapshot = snapshot Dim NewMessage As Map = snap.Value 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") Log(NewMessage) '(MyMap) {time=1500126681816, From=Someone, Message=bla bla bla bla :-), Title=Hello world!} Dim dt As Long = NewMessage.Get("time") lv.AddTwoLines2("From "&NewMessage.Get("From")&": "&NewMessage.Get("Title"), DateTime.Date(dt)&": "&NewMessage.Get("Message"),NewMessage) 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("---_onChildAdded()") End Sub Sub chat_onChildChanged(snapshot As Object, child As String, tag As Object) 'Log($"chat_onChildchanged(${child},${tag})"$) End Sub Sub chat_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object) 'Log($"chat_onComplete(${resultCode},${resultMessage},${tag})"$) End Sub Sub chat_onChildMoved(snapshot As Object, child As String, tag As Object) 'Log($"chat_onChildMoved(${child},${tag})"$) End Sub Sub chat_onChildRemoved(snapshot As Object, tag As Object) 'Log($"chat_onChildRemoved(${tag})"$) End Sub Sub chat_onDataChange(snapshot As Object, tag As Object) Log($"chat_onDatachange(${tag})"$) If snapshot <> Null Then Dim snap As DataSnapshot = snapshot If snap.IsInitialized Then If snap.Value <> Null And snap.Value <> "null" Then 'Log("Snapshot value is NOT null. Ok. Need to check content") If snap.Value Is Map Then Log("Value type Map: "& GetType(snap.Value)) 'fbdb = snap.Value Log("Value = "&snap.Value) else if snap.Value Is List Then 'Log("Value type List: "& GetType(snap.Value)) Dim customers As List = snap.Value Log("chatListSize: "&customers.Size) else if snap.Value Is String Then 'Log("Value type String: "& GetType(snap.Value)) Dim val As String = snap.Value Log("Value="&val) Else Log("Value type unknown: "& GetType(snap.Value)) End If 'users/b0d0d7f9b81140c3/) 'Dim json As JSONParser 'json.Initialize(snap.Value) 'Dim root As Map = json.NextObject 'Log(json.NextObject) Else 'Log("Snapshot value is null") 'Dim m As Map 'm.Initialize 'myref.Value = CreateMap("Username":"DonManfred","Age":49) End If Else Log("Snapshot not initialized") End If Else Log("Snapshot is null") End If 'Dim keys As List = snap.Children 'Log(keys.Size) 'Log(snap.Children) End Sub Sub customers_onCancelled(errnum As Int,error As String, errObj As Object, tag As Object) Log($"customers_onCancelled(${errnum},${error},${tag})"$) End Sub Sub customers_onChildAdded(snapshot As Object, child As String, tag As Object) Dim snap As DataSnapshot = snapshot Dim NewMessage As Map = snap.Value 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") Log(NewMessage) custmap.Put(child,NewMessage) Log($"customers_onChildAdded(${child},${tag}, SizeofCustomers: ${custmap.Size})"$) '(MyMap) {address=789 28th Street, home_phone=NULL, job_title=Purchasing Manager, last_name=Raghav, city=Memphis, web_page=NULL, company=Company BB, business_phone=(123)555-0100, fax_number=(123)555-0101, attachments=, mobile_phone=NULL, zip_postal_code=99999, state_province=TN, id=28, email_address=NULL, notes=NULL, country_region=USA, first_name=Amritansh} 'Dim dt As Long = NewMessage.Get("time") lv.AddTwoLines("From: "&NewMessage.Get("first_name")&" "&NewMessage.Get("last_name"),"(ID "&NewMessage.Get("id")&") "&NewMessage.Get("address")) 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("========= NEW MSG =============") 'Log("---_onChildAdded()") End Sub Sub customers_onChildChanged(snapshot As Object, child As String, tag As Object) Log($"customers_onChildchanged(${child},${tag})"$) Dim snap As DataSnapshot = snapshot Dim NewMessage As Map = snap.Value 'Log("========= CHANGED =============") 'Log("========= CHANGED =============") 'Log("========= CHANGED =============") 'Log(NewMessage) custmap.Put(child,NewMessage) End Sub Sub customers_onComplete(resultCode As Int, resultMessage As String, result As Object, tag As Object) Log($"customers_onComplete(${resultCode},${resultMessage},${tag})"$) End Sub Sub customers_onChildMoved(snapshot As Object, child As String, tag As Object) Log($"customers_onChildMoved(${child},${tag})"$) Dim snap As DataSnapshot = snapshot Dim NewMessage As Map = snap.Value 'Log("========= MOVED =============") 'Log("========= MOVED =============") 'Log("========= MOVED =============") 'Log(NewMessage) custmap.Put(child,NewMessage) End Sub Sub customers_onChildRemoved(snapshot As Object, tag As Object) Log($"customers_onChildRemoved(${tag})"$) Dim snap As DataSnapshot = snapshot Dim NewMessage As Map = snap.Value 'Log("========= REMOVED =============") 'Log("========= REMOVED =============") 'Log("========= REMOVED =============") Log(NewMessage) End Sub Sub customers_onDataChange(snapshot As Object, tag As Object) Log($"customers_onDatachange(${tag})"$) If snapshot <> Null Then Dim snap As DataSnapshot = snapshot If snap.IsInitialized Then If snap.Value <> Null And snap.Value <> "null" Then 'Log("Snapshot value is NOT null. Ok. Need to check content") If snap.Value Is Map Then 'Log("Value type Map: "& GetType(snap.Value)) fbdb = snap.Value 'Log("FBDBroot set...") else if snap.Value Is List Then 'Log("Value type List: "& GetType(snap.Value)) Dim customers As List = snap.Value Log("customerListSize: "&customers.Size) else if snap.Value Is String Then 'Log("Value type String: "& GetType(snap.Value)) Dim val As String = snap.Value Log("Value="&val) Else Log("Value type unknown: "& GetType(snap.Value)) End If 'users/b0d0d7f9b81140c3/) 'Dim json As JSONParser 'json.Initialize(snap.Value) 'Dim root As Map = json.NextObject 'Log(json.NextObject) Else Log("Snapshot value is null") 'Dim m As Map 'm.Initialize 'myref.Value = CreateMap("Username":"DonManfred","Age":49) End If Else Log("Snapshot not initialized") End If Else Log("Snapshot is null") End If 'Dim keys As List = snap.Children 'Log(keys.Size) 'Log(snap.Children) End Sub