Tuesday 30 July 2019

"WorkManager" a server less android application using Kotlin and Firestore

WorkManager is a serverless android application where data is saved in Firestore. We will be creating a cloud function to send the push notification. You can use this application as a reference for implementing Firestore.


Prerequisite




Getting Started

In Firebase there are mainly two main database concepts. One is a Real-time database and the other one is Firestore. Firestore is in beta mode, which means code can change. In this application, We are concentrating on Firestore.

Project creation in firebase

Step 1. Create a project in Firebase Link
Step 2. Provide details like the Package name, SHA1, etc to configure
Step 2. On completing step2, a file named google-services.json.Download this file and add to the app folder. With this process, you are done with configuration.

Push Notification in a serverless application

Since we don't have a server to handle push notification, We are going to develop a cloud function and host them in Googe cloud functions. On hosting you can view them on your firebase console. To start with, you need to install Nodejs on your local system. With the help of nodejs framework and firebase tool, you need to create a cloud function. On completing this process you can upload it on to firebase cloud function. I have kept everything simple in here. The logic is quite simple, We have a collection(For the time being let us assume collection to be a table) named Notification. Whenever there is an entry in notification collection, we need to trigger our cloud function. This cloud function will send the push notification.
Step 1. Install node.js on your local system Click Here to download Nodejs
Step 2. Make a folder for cloud function and open command prompt here
Step 3. Use this command to install firebase tools npm install -g firebase-tools
Step 4. Now login to your account using firebase login
Step 5. Now configure your application using, on completing you can find an index.js file
Step 6. add necessary code in the index.js file and upload the function using firebase deploy
I have added the cloud function code in the firebase function folder please have a look.
[Similarly, you can host your admin website in Firebase Hosting section(I will be updating same)]

"WorkManager" a server less android application using Kotlin and Firestore

WorkManager is a serverless android application where data is saved in Firestore. We will be creating a cloud function to send the push not...