Hello 👋 How can we help?

Enable push notifications for Android (optional)

Push notifications are great for real-time messaging and informing your app users that there is a new message for them.
Written by Alex
Updated 1 month ago

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:

  1. Add google-services.json to the app/ folder 
  2. 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.3.3'  // 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
Don't forget to configure your Andro                  id app and to add the Firebase API key from Firebase Console

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);

        boolean isOurMessage = remoteMessage.getData().get("some_key").equals("isOurMessage") ;

        if (isOurMessage) {
            //do something yours
        } else{
            HelpCrunch.showNotification(remoteMessage);
        }
    }
}

Did this answer your question?