Push Notification
Last updated
Was this helpful?
Last updated
Was this helpful?
You can set up push notifications to notify your end users for incoming chat messages. For managing push notifications, you must have a .
Note: If you already have a Firebase account and code to retrieve firebase registration token for the client app instance, then skip this section and move to section.
google-services.json
fileIf you haven't already added firebase to your project, add
Once you're done with above setup, download the google-services.json file
from firebase console, click Settings icon -> Project settings -> General -> Scroll to bottom -> Select your app -> Click the google-services.json
button.
Place the google-services.json
file under the root directory of your app.
From firebase console, click Settings icon -> Project settings
Once you clicked project settings select Cloud Messaging tab under Settings. Under Project Credentials, copy your Server Key which is highlighted blue in the following image.
Note: Make sure you copy the Server key and not the Legacy key or Sender ID.
Go to in Kommunicate dashboard and update the FCM server key under the 'GCM/FCM Key' section. You can find it in the Settings -> Cloud Messaging -> Server Key section of your Firebase console.
Open your project level(root level) build.gradle
file and under buildscript
node, add the below classpath inside dependencies
:
Open your app level build.gradle
and at the bottom of the file apply the plugin as below:
If you do not have any push notification setup, kommunicate will do it internally for you. If you already have the setup, follow the next section.
If you already have the push notification setup, follow the below steps.
The first step in the setup would be to send the deviceToken to Kommunicate. This needs to be done in onNewToken
method of your FirebaseMessagingService
subclass. The onNewToken
method is called whenever firebase updates the deviceToken on that device.
Note:
onNewToken
method providesregistrationId
, this is the deviceToken.
Use the below code to send the token to Kommunicate.
For Receiving FCM Notifications in your app, add the following code in your FirebaseMessagingService
inside onMessageReceived(RemoteMessage remoteMessage)
:
To set the notification small icon, place the below metadata in your AndroidManifest.xml
file under tag
:
Note: Android version 6.0 onwards, android automatcially converts the small icon color to monochrome. While some custom ROM devices do show colored icons, it is recommended that you use a shaped icon with some transparent background instead of round solid icons as a small icon.