Chapter 9. Let us Chat in a Smart Way - Notifications and More
The previous chapter helped us in building a conversational messaging application, but the Wear app had a very normal user interface with no notifications whatsoever. Notification is a very important aspect of a messaging application, but it needs complex infrastructure to process the notification. When the sender sends a message to the receiver, the receiver should get a notification conveying certain information, such as the sender name, and a quick message preview.
Notification is a component in Android that we can use to display information. In the case of a messaging application, the receiver should get the push notification to instantiate the notification component. So, whenever there is a real-time database update in Firebase, both the handheld device and the Wear device should get the notification. Thankfully, we don't need a server to handle the notification; Firebase will handle push notifications for your messaging...
Firebase functions are the solution for database triggers and many more server-related executions. Instead of hosting a server, which listens to Firebase database changes and then fires the notification, we shall utilize one of the Firebase technologies to complete this task. Firebase functions has an efficient control on all the Firebase technologies, such as Firebase authentication, storage, analytics, and so on. Firebase functions can be used in various aspects; for example, when your analytic cohorts meet some milestone, you can send targeted notifications, invites, and so on. Any server level business logic that you might want to implement in your Firebase system has been made with Firebase functions. We will use Firebase functions for sending push notifications whenever a database trigger occurs. We need an entry level JavaScript understanding to complete this task.
To get started on Firebase functions, we need Node.js environment that you can install it from https...
In this chapter, you have learned how to use Firebase functions to send push notifications and to use the notification component from the Wear support library. Notifications are integral components in smart devices; they play a crucial role by reminding users. We have understood the NotificationCompat.Builder
class and the WearableExtender
class. We have also explored the input method framework and the easiest way to reply with multiple reply mechanisms, such as emojis, voice support, and so on.