Push Notification
Overview
You can set up push notifications to notify your end users for incoming chat messages. For managing push notifications, you must have a Firebase account.
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 Push notification setup section.
1) Get the google-services.json
file
google-services.json
fileIf you haven't already added firebase to your project, add Firebase to your Android project
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 thegoogle-services.json
button.Place the
google-services.json
file under the root directory of your app.
2) Obtain server key from firebase
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.
3) Add your server key to Kommunicate
Go to Push notification section 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.
4) Gradle file configuration
Open your project level(root level)
build.gradle
file and underbuildscript
node, add the below classpath insidedependencies
:
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.
Already have the push notification setup?
If you already have the push notification setup, follow the below steps.
1) Send the device token to Kommunicate
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.
2) Receive push notifications
For Receiving FCM Notifications in your app, add the following code in your FirebaseMessagingService
inside onMessageReceived(RemoteMessage remoteMessage)
:
Set notification small icon
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.
Last updated