Greetings People!
Today I am going write about Firebase, which will be targeting mostly the people who don’t know what Firebase is.
What is Firebase?
Before Google owned Firebase. It was real-time database. Now it has many other features like Cloud Messaging, Storage and etc. Read more
Lets start with making a simple application. Open https://console.firebase.google.com/. Login with your google account. Click Create New Project add name and location to it then click Create Project.
You’ll be redirected to your project’s dashboard. Then click on Add Firebase to your Android app
Add your package name. I have already created a project so I added its name. Then click Add App.
After clicking that you’ll get a google-services.json file.
Open your project in Android Studio and in the Explorer paste your google-services.json file under app folder.
In your Project build.gradle.
And in your Module build.gradle.
Click on your Database then click Rules. Make Read and Write both to true.
After that open your activty_main.xml and add a Edit text and a Button, and reference in a the MainActivity.
Create Firebase database object by using the following code:
FirebaseDatabase database = FirebaseDatabase.getInstance(); final DatabaseReference myRef = database.getReference("Sample Firebase");
Now its time to set values to Firebase. In your button listener.
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Get the text from Edit text String text = editText.getText().toString(); //set it on Firebase myRef.setValue(text); } });
In order to listen to changes to Firebase.
myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Invokes whenever data is updated or changed String value = dataSnapshot.getValue(String.class); Toast.makeText(getApplication(),"Value Changed To:"+value,Toast.LENGTH_SHORT).show(); } @Override public void onCancelled(DatabaseError databaseError) { } });
With this being done. You’re all set up and now ready to set data to Firebase.
Run your project and test by sending data.
Testing on Simulator.
You can find this project on Github.
If you have any questions leave a comment. I’ll get back to you as soon as I can. 🙂
See ya!
This article covers some important things you must know when you are considering a move…
What is Unit Testing? In its simplest term, unit testing is testing a small piece…
In this article, you will learn about a type of Creational Design Pattern which is…
In this tutorial, you will go through the use of targets to achieve two separate…
In this article, you will learn about a type of Structural Design Pattern which is…
In this article you will learn about a type of Creational Design Pattern which is…
View Comments
Too difficult for beginner please make it simple.
Can you point me out from where?
You actually make it seem really easy together with your presentation however I to find this topic to be actually something that I believe I might never understand.
It sort of feels too complex and very vast for me. I am having a look ahead on your
next publish, I'll attempt to get the grasp of it!
First off I want to say terrific blog! I had a quick question which I'd like to ask if you do
not mind. I was interested to know how you center yourself and clear your thoughts prior to writing.
I've had a difficult time clearing my thoughts in getting my thoughts
out. I do enjoy writing however it just seems like the first 10 to
15 minutes are generally lost just trying to figure out how to
begin. Any suggestions or tips? Thanks!
Hi,
Really appreciate your kind words.
When I started writing blogs, I had a purpose which was to not let another developer go through the same pain of implementing something as I did. So this what helps and motivates me to write. Before writing I start to research on the thing I am going to write on, and create a sample project. After I'm done with the sample app, more than half of my work is done then all I have to do is come up with some words to explain what I have done. Hope this helps.
Cheers!
I don't even know how I ended up here, but I thought this post was great.
I do not know who you are but certainly you are going to a famous blogger if you
aren't already ;) Cheers!
Thanks for the kind words. *fingers crossed*
Hello my family member! I want to say that this article is amazing, great written and come
with almost all significant infos. I'd like to see more posts like
this .
Hurrah! In the end I got a website from where I know how to really get valuable data regarding my study and knowledge.
bookmarked!!, I like your site!
Your style is sο unique inn comparison tо otһeг folks I have read stuff from.
Ι aρpreciate yоu for posting ԝhen you've got the opportunity,
Guess Ӏ'll ϳust book mark this blog.
I have to thank you for the efforts you have put in penning
this site. I am hoping to see the same high-grade content by you in the
future as well. In truth, your creative writing abilities has encouraged
me to get my own site now ;)
I've been surfing online more than three hours today,
yet I never found any interesting article like yours. It's pretty worth
enough for me. Personally, if all website owners and bloggers made good content as you did, the internet will be much more useful than ever before.