Use Connection ServiceIf you want to use the System’s native call service to handle calls, please refer to our guide on Android - Connection Service
I want to checkout the sample app
Android Push notifications sample appView on Github
Firebase Project Setup
Visit Firebase Console and login/signup using your Gmail ID.Step 1: Create a new Firebase Project
On your Firebase Console, create a new project.
- You give a name to your project
- Add Google Analytics to your project (Optional)
- Configure Google Analytics account (Optional)
Step 2: Add Firebase to your Android App
- Click on the Android icon as shown on the screen below.

-
Register your Android app by providing the following details:
- Android Package name
- App nickname (optional)
- Debug signing certificate SHA-1 (optional)

- Download the
google-services.json
file and place it in the required location in your project.

- Add Firebase SDK by copying and pasting the snippets in the Project-level
build.gradle
file.

- Add Firebase SDK by copying and pasting the snippets in the App-level
build.gradle
file.

- Click on ‘Continue to Console’ to finish the setup.
Step 3: Download the service account file

Extension settings
Step 1: Enable the extension
- Login to CometChat and select your app.
- Go to the Extensions section and Enable the Push Notifications extension.
- Open the settings for this extension and save the following.

Step 2: Save your settings
On the Settings page you need to enter the following:- Set extension version
- If you are setting it for the first time, Select
V2
to start using the token-based version of the Push Notification extension. - If you already have an app using
V1
and want to migrate your app to useV2
, then SelectV1 & V2
option. This ensures that the users viewing the older version of your app also receive Push Notifications. - Eventually, when all your users are on the latest version of your app, you can change this option to
V2
, thus turning offV1
(Topic-based) Push Notifications completely.
- Select the platforms that you want to support
- Select from Web, Android, Ionic, React Native, Flutter & iOS.
- Notification payload settings
- You can control if the notification key should be in the Payload or not. Learn more about the FCM Messages here.
- Push payload message options

- The message metadata includes the outputs of the Thumbnail Generation, Image Moderation, and Smart Replies extensions. You may want to retain this metadata if you need to customize the notification displayed to the end user based on these outputs.
- Notification Triggers

-
Select the triggers for sending Push Notifications. These triggers can be classified into 3 main categories:
- Message Notifications
- Call Notifications
- Group Notifications
- These are pretty self-explanatory and you can toggle them as per your requirement.
Android App Setup
In the Firebase Project setup, we did the following things:- Added google-services.json file to the project.
- Added the required Firebase SDK snippets to the Project-level build.grade file.
- Added the required Firebase SDK snippets to the App-level build.gradle file.
Step 1: Register the FCM Token on user login
- Initialize CometChat and then login your user.
- On successful login, you can register the obtained FCM Token using
CometChat.registerTokenForPushNotification()
function call. (You can see the process of getting the FCM Token in the next step)
Step 2: Receive notifications
- The FCM Token can be received by overriding the
onNewToken()
method. This token is stored as a String variable. You can choose to store it in SharedPreferences as well. - To receive messages, you need to override the onMessageReceived(RemoteMessage remoteMessage).
- PushNotificationService.java has the code that provides a way you can handle messages received from CometChat users and groups.
- CallNotificationAction.class is a BroadcastReceiver which is used to handle call events when your app is in the background state.
- Since Android O, there have been certain restrictions added for background tasks and users cannot launch intent directly from the service. More details here.
- We suggest you to create notification channel inside your application class. After Android O, it is necessary to register notification channel to allow notifications of your apps.
- You also need to add both of the above-mentioned files in your AndroidManifest.xml to make Push notification work in the background as well.
Advanced
Sending Custom Notification body
Push notification has 2 parts, namely, the notification title and notification body. The title can be: a. Name of the sender in case of one-on-one message. (E.g.: Nancy Grace) b. Name of the sender followed by group name for group messages (E.g.: Nancy Grace @ Hiking Group) The body of the message depends upon the type of message being sent. You can send a custom body by specifying thepushNotification
key followed by some user-defined string for the notification body inside metadata
while sending the message.
The following code shows an example of a Custom body using a message of category=custom. This is however not just limited to a custom category of messages.
Converting Push Notification Payloads to Message Objects
CometChat provides a methodCometChatHelper.processMessage()
to convert the message JSON to the corresponding object of TextMessage
, MediaMessage
, CustomMessage
, Action
or Call
.
This code needs to be added to the onMessageReceived()
method of the FirebaseMessagingService
class.
Type of Attachment can be of the following the type
CometChatConstants.MESSAGE_TYPE_IMAGE
CometChatConstants.MESSAGE_TYPE_VIDEO
CometChatConstants.MESSAGE_TYPE_AUDIO
CometChatConstants.MESSAGE_TYPE_FILE
Handle Push Notification Actions.

onMessageReceived(RemoteMessage message)
. You need to call CometChat.processMessage()
method to process push notification payload.
CometChatMessageListActivity is part of UI Kit Library. You can replace CometChatMessageListActivity with your required class.