Check out My First Android Library( Firebase JSON Reference)

As it’s small one but , I think it will be helpful to developer. This library is to get Firebase Reference JSON value.
While using ValueChangeListener to get data, I found some difficulties because it ran the code every time when data got change. So I wanted to get rid of this ValueChangeListener to get the data of the given reference.
That’s the reason I developed FirebaseJSONReference.
Details need in Release 0.1.1
Firebase URL: “https://example.firebaseio.com"
Reference URL: “/data/value”
User Token: Auth token from Firebase
How to get Auth Token :-
FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mUser.getIdToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String token = task.getResult().getToken();
// Send token to your backend via HTTPS
// ...
} else {
// Handle error -> task.getException();
}
}
});
Add Dependencies :-
Add following to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add following dependency
dependencies {
compile 'com.github.harsh2011:FirebaseJSONReference:0.1.1'
}
Demo of Library:-
How to use it.
FirebaseJSONReference firebaseJSONReference = new FirebaseJSONReference(MainActivity.this);
firebaseJSONReference.setFirebaseDatabaseURL("https://example.firebaseio.com");
firebaseJSONReference.setFirebaseRef("/requestlist");
firebaseJSONReference.setAuth("auth token");
firebaseJSONReference.setResponseListener(new ResponseListener() {
@Override
public void onResponse(String s) {
System.out.println("response:"+s);
try {
//JSONobject response
JSONObject main = new JSONObject(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
//build the request
firebaseJSONReference.build();
//execute the request and get response in Response Listener
firebaseJSONReference.execute();
