Check out My First Android Library( Firebase JSON Reference)

Harsh Patel
Jul 20, 2017 · 2 min read

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();

)

Harsh Patel

Written by

Computer Science || Android, Computer Vision || Blockchain

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade