We believe that push notifications are a great way to add real-time messaging to your application and inform your app users that there is a new message from HelpCrunch (i.e. from your admin dashboard). It allows you to stay in touch with your users even when the application is not in the foreground.
The HelpCrunch Mobile SDK does not necessarily require implementing push notifications. Without push notifications, your app's users will still be able to receive new messages, but they will only discover them after opening the HelpCrunch window.
We use Firebase Cloud Messaging (FCM). Is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
So, to add push notifications to your app, you'll need:
- Add google-services.json to the app/ folder
- To enable Firebase products in your app, add the google-services plugin to your app/build.gradle file. In your root-level (project-level) Gradle file (build.gradle), add rules to include the Google Services plugin. Check that you have Google's Maven repository as well.
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:4.4.0' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
//In your module (app-level) Gradle file (usually app/build.gradle), add a line to the bottom of the file.
apply plugin: 'com.android.application'
android {
// ...
}
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
Adding HelpCrunch notifications to a project with notifications
If you have a overriding of the FirebaseMessagingService class in your project, then the push messages will come into it.
In this case, you need to separate your notifications from ours. The following code does a great job:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (HelpCrunchExt.isHelpCrunchMessage(remoteMessage)) {
HelpCrunch.showNotification(remoteMessage);
} else {
//Do something yours
}
}
}
FirebaseMessagingService conflicts
Please note that our service has a very high priority. If you encounter a problem when you do not receive your notifications in the application, then increase the priority of your FirebaseMessagingService over 9990 and follow the instructions from the Adding HelpCrunch notifications to a project with notifications category.
Service initialization example:
<service
android:name=".YourFirebaseMessagingService"
android:exported="false">
<intent-filter android:priority="9991">
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>