Saturday, March 20, 2021

Building a chat application on Android development platform: (continued...)

 Addendum: 

Firebase Cloud messaging Android extension provides message broker abilities for a client application and it works well on Android.  Client applications use the FirebaseMessaging API and must have Android Studio 1.4 or higher. Firebase can be added to the project if the device or emulator has Google Play services installed.  


The Android app can be connected to the Firebase using Option 1. Firebase console or Option 2. Android Studio Firebase assistant. The Option 1 requires the Firebase console to download the Firebase configuration files and then moved into the Android project. The Firebase configuration file can be used when the Google services plugin 'com.google.gms:google-services:4.3.5' can be added to the Gradle file. The Firebase SDK can be added to the application with the ‘implementation platform('com.google.firebase:firebase-bom:26.7.0')’   The Option #2 uses the Firebase Assistant which has preconfigured workflows to add a Firebase product to the application. 

If Kotlin is used in the Android application, the Kotlin extension (KTX) libraries need to be added.  


Any application written using Firebase needs to be registered. Once the configuration file is added, the application manifest also needs to be edited. A service that extends the FirebaseMessaging Service needs to be added. This Service extends the base class to add functionality for receiving notifications in the foreground, receiving data payload, and sending upstream messages. Metadata elements can be optionally added to the manifest to set icon and color. Notification channels can be added on a per queue basis. 


When the application is started, during initial time, the SDK generates a token for the client application. This new token is used with the onNewToken overridden method. Tokens can be rotated so the application must always retrieve the latest updated registration token. The current token can be retrieved using the FirebaseMessaging.getInstance().getToken() Token autogeneration can be prevented by disabling the Analytics collection and Firebase Cloud Messaging auto initialization. 

 

The storage can also be provisioned via Firebase. Cloud Firestore is just right for this case. It is a flexible scalable database for mobile, web and server development from Firebase and Google cloud. One of the primary advantages of this database is that it caches that data that the application is using which makes it easy to access the data even when the device is offline. 


It is a cloud hosted NoSQL database, and it is accessed directly via native SDKs as well as REST APIs. Data is stored in documents; documents are kept in collections and the data primitives support complex objects. Realtime listeners can be registered to retrieve just the updates instead of the entire database. 

 

 

No comments:

Post a Comment