Sending a chat message to the user who’s currently offline in your mobile app will result in them receiving a push notification, like the one from regular messengers.
In order for push notifications to work we are using Firebase Cloud Messaging (FCM). If you already have a Firebase-project with notifications on, skip this step. Choose a name for your project and click Create project:
Select Cloud Messaging after you are done with project settings:
Select the Android icon:
Set your package name and click Register App:
Click Download google-services.json, to load the configuration file. Put it into your app level.
Click Next and add dependency to the file of build.gradle on the app level:
dependencies {
implementation 'com.google.firebase:firebase-messaging:17.+'
}
Don’t forget to apply a plugin at the end of the same file:
apply plugin: 'com.google.gms.google-services'
Click Next.
Select your project in the Firebase console, go to Project settings, open Service accounts tab. Click Generate New private key. It will prompt a JSON-file with the key to download.
You can manage the keys in Google Cloud Platform settings. To do so, open the Firebase console, go to the Service accounts tab and click the Manage service account permissions link. While in Dashly, go to the Settings → Developers section and upload your key.
A thumbnail can be set up using the following method:
Carrot.setNotificationIcon(notificationIconId)
where notificationIconId
is the thumbnail source ID.
This step may be of importance for the apps that are currently using FCM to work with their own push notifications. Here is how to configure your FirebaseMessagingService
:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived (RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
if (data.containsKey(NotificationsConstants.CQ_SDK_PUSH) && "true".equals(data.get(NotificationsConstants.CQ_SDK_PUSH))) {
Carrot.sendFirebaseNotification(remoteMessage);
} else {
//DO HOST LOGIC HERE
}
}
}
If you are having issues with the FCM configuration, check the following:
Check if you have enabled the Send a push notification option for manual messages
Check if push notifications for the app are allowed on your test device: Settings → Notifications and status bar → Notification manager (path may differ depending on the Android version).
Check Push Server API key.
Check if google-services.json is located in the correct directory.