Here I will demonstrate a way to set up the Firebase service for a generic Android application.
Preparatory steps, registration, and authorization
First I create a new empty markup project, called com.shakuro.firebase by clicking Create a project on the console – main Firebase administration tool.
To add Firebase to an Android app, do the following:
After that don’t forget to open your project in Android Studio and copy the downloaded google-services.json file into the Android apps module root directory.
Now in the build.gradle project’s level, let’s add the dependency of the relevant library.
Also, the following line needs to be added in the end of build.gradle under the app catalog:
This line connects a certain plugin to the Google Service project. This plugin processes the configured JSON and taps into the basic libraries of com.google.gms:google-services.
Voila! Firebase is bound to the app which can now be assembled.
To make it simple, let’s log in to the console, open the created database, and add JSON right in this pretty interface.
Now add our activity:
At this point everything is almost done, however, there is no access to the database. For the testing purposes and simplicity, let’s make the database fully accessible by changing the access rules from “null” to “true”.
Now let’s launch the application.
And last thing – configure the button to process data into database.
It’s all good, but could be better if the authorization was available. Not a problem, let’s add authorization into our mini-project.
The method itself and the sign in exception handler:
- For messages storage we used the Realtime database and services for cloud NoSQL database administration. They provide storage and synchronization for all the connected devices. The new Firebase build the data is saved on the hard drive to remain responsive during disconnect and certainly, the data is synchronized after the connection is reestablished.
- For authorization we used the Google.auth service, identification and user management tool. The identification is supported through the email-password pair, social networks (Facebook, Twitter, GitHub, Google+), and can be integrated with other existing authorization systems.
- For remote configuration we used the Remote Config service that allows us to change and update parts of the apps without having to update the entire packages and go through the long checks in application stores. For safety reasons and performance you will need to figure out what you want to be updated remotely and set the required key-value pair parameters beforehand. After that you can change the application layout and functional by changing these parameters at the backend. For example, you can style the app’s layout update for a holiday and then switch back with no additional reviews. Like many other Firebase elements, notifications are integrated into Firebase Analytics. Thus, you can filter groups of users (formed by hundreds of parameters) and send updates specifically to them.
To wrap it up, I believe that from just a data storage service, Firebase turned into a universal platform for mobile developers with a friendly interface and super simple app integration mechanism. As you just saw, you can add Firebase to your app in a couple of clicks.
I think it would be a mistake to neglect such a useful and interesting tool. Try it out! It’s awesome.