I am trying to make a basic connection to firebase within a Java app, and using the basic code provided I am unable to get any response at all.
Here is the code I am using:
package fix;
import com.firebase.client.*;
public class Main {
public static void main(String args[]) throws Exception {
String url = "https://----.firebaseIO.com/";
Firebase dataRef = new Firebase(url);
dataRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println("data");
}
@Override
public void onCancelled() {
System.err.println("Listener was cancelled");
}
});
System.out.println("hi");
}
}
The library seems to be loading fine. Any suggestions?
Update
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Raising events for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Doing onDiff with changes: []
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Raising events for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Doing onDiff with changes: []
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Adding Value Event Listener callback for path: /
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] PersistentConnection: pc_0 - Listening on / for [{}]
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] PersistentConnection: pc_0 - Adding listen params: [{}]
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] EventRaiser: Raising 0 event(s)
[java] wait
[java] wait
[java] wait
[java] wait
The java support for Firebase is intended to extends its server side functionality by using Firebase's sdk. To query on Firebase realtime database or Firestore, you should write your android/ios app and/o through a web app written on javascript.
Open the Firebase Assistant: Tools > Firebase. In the Assistant pane, choose a Firebase product to add to your app. Expand its section, then click the tutorial link (for example, Analytics > Log an Analytics event). Click Connect to Firebase to connect your Android project with Firebase.
I believe the probelm is that, unlike Node.js which keeps running waiting for events and callbacks to fire, Java quits when it reaches the end of the main method. You'll want to keep the main thread from quitting. Something like this should keep the main thread from terminating.
while(true) {
Thread.Sleep(10000); //Sleep 10 seconds
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With