Javatpoint Logo
Javatpoint Logo

Types of Message

Using Firebase Cloud Messaging, we can send three types of messages, i.e., Notification Message, Data Message, and the message with both Notification & Data Payload.

1) Notification Message

Firebase SDK has handled notification messages itself. Typically, the notification message includes the title, icon, message, etc. These messages can also be sent from the Firebase console UI. By sending this type of message, we will not have much control over the information. The notification will appear automatically when the app is in the background.

A notification is a message which Android shows outside of our app's UI for providing users with reminders, communication with other people, or other timely information about our app. Users can tap on the notification to open our app or take action directly from the notification.

Firebase Types of Message

The notification design is determined by the system template - the content for each part of the template is defined by our app. Some information on the notification only appears in the expanded view. The most common parts of notification are as follows:

  1. Small icon
    It is essential to set a small icon in the notification. This small icon is set with setSmallIcon().
  2. App name
    The application name is provided by the system.
  3. Timestamp
    The timestamp is also provided by the system, but we can override it with setWhen() function or hide it with setShowWhen() function.
  4. Title
    It is also optional and set with setContentTitle() function.
  5. Text
    Text is optional and set with setContentText().
  6. Large icon
    This is optional, and we use it for contact photos. We don't use it for our app icon and set with setLargeIcon() function.

2) Data Message

Data messages are handled by the Android app. If we want to send some additional data along with the information, then we can add such messages. But, it is not possible to send these messages through the Firebase console. To send notifications using the Firebase API, we must have server-side logic. We must use the data key while sending this message.

We can use data messages to send custom data elements to a client application. However, FCM places a 4KB limit on these data messages, so if our payload is greater than 4KB, we must obtain additional data using the WorkManager or JobScheduler API.

3) Messages with both Notification and Data payload

Both Notification and Data payload can also be contained in a message. Sending of these types of messages is handled in two scenarios depending upon the app state, i.e., background and foreground. We can use both the notification and data keys for these messages.

When the app state is in the background, the apps receive the notification payload when the user taps on the notification, and when in the foreground, the app receives a message object with both payloads available.

FCM Console

Now, we will create an Android project and add it with the Firebase either from Google Assistant or manually. After that, we will move to the FCM console (Firebase->Grow->Cloud Messaging).

Firebase Types of Message

Click on Send your first message.

Firebase Types of Message

After clicking on Send your first message, it will ask to fill a few of the fields such as notification title, notification text, notification image that is optional, and notification name, which is also optional.

Firebase Types of Message

After filling all the fields, click on Next.

Firebase Types of Message

After clicking on Next, it will ask for the Target either User segment or Topic. We will select the app for the target user and click on Next.

Firebase Types of Message

Firebase Types of Message

When we click on the Next, it will ask for the Scheduling and click on Next again.

Firebase Types of Message

After that, it will ask for the Conversion events. We can do this, but it is optional. So, we can ignore it and proceed further.

Firebase Types of Message

After that, it will ask for some additional options, which are also optional. These are notification channels, custom data, sound, and expires, etc. After that, we will click on the Review.

Firebase Types of Message

After publishing, we can see the notification in the console.

Firebase Types of Message

We can duplicate notification if we want to get insight on message delivery to our app. We can go to the reporting dashboard, which records a number of messages sent in the device. It also has some data for impressions notifications which are seen by users, but we will go through more of the notification composer.

Firebase Types of Message

Firebase Types of Message

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA