Mobile Push Notifications in Zoho PageSense

Learn how to set up Mobile Push Notification in Android devices

1. Ensure you have enabled Push Notification inside PageSense dashboard.
2. Add Firebase to your Android project.  
3. In the top-left pane, click on the settings icon beside Project Overview.
4. Click Project settings.

5. Inside Project Settings, navigate to Service accounts.
6. Click Generate new private key.

7. This will generate a service account JSON file containing the Private key.
8. Download the JSON file and upload it to your PageSense dashboard.
Info
Learn how to upload JSON file? Under Android setup, refer to points six and below.
9. Ensure the Firebase Cloud Messaging (FCM) API (V1) is enabled under the Cloud Messaging of the FCM console.

10. If it's disabled, click the three-dot icon beside the Firebase Cloud Messaging API (V1), and select Manage API in Google Cloud Console and click Enable.



How to set up a Firebase Cloud Messaging (FCM) on client app for Android:

Once FCM is setup, follow the below steps to begin receiving notifications in the device.
1. Add the below code to the app level manifest file. This enables us to receive notification from Firebase.
  1. <service android:name=".NotificationFCMReceiver" 
     android:exported="false"> 
     <intent-filter> 
            <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
     </intent-filter> 
     </service> 
2. Add the class which extends FirebaseMessagingService to your App’s project. Please refer to the below code based on your preferred language:
For JAVA, use the below code:
  1. import com.google.firebase.messaging.FirebaseMessagingService;
  2. import com.google.firebase.messaging.RemoteMessage;
  3. import com.zoho.pagesense.android.PSNotification;
  4. public class NotificationFCMReceiver extends FirebaseMessagingService {
  5.     @Override
  6.      public void onNewToken(@NonNull String s) {
  7.                  super.onNewToken(s);
  8.                  PSNotification.sendDeviceToken(s);
  9.      }
  10.     @Override
  11.      public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
  12.                  super.onMessageReceived(remoteMessage);
  13. if(PSNotification.isFromPageSensePlatform(remoteMessage.getData())) {
      PSNotification.showNotification(remoteMessage.getData(),
  14.                           com.zoho.pagesense.android.R.drawable.notification_bg);
  15.                  }
  16.        }
  17. }
For KOTLIN, use the below code:
  1. import com.google.firebase.messaging.FirebaseMessagingService
  2. import com.google.firebase.messaging.RemoteMessage
  3. import com.zoho.pagesense.android.PSNotification
  4. class NotificationFCMReceiver : FirebaseMessagingService() {
  5.     override fun onNewToken(s: String) {
  6.                 super.onNewToken(s)
  7.                  PSNotification.sendDeviceToken(s)
  8.      }
  9.     override fun onMessageReceived(remoteMessage: RemoteMessage) {
  10.                super.onMessageReceived(remoteMessage) 
  11.                if (PSNotification.isFromPageSensePlatform(remoteMessage.data)) {
  12.                          PSNotification.showNotification(remoteMessage.data,
  13.                          com.zoho.pagesense.android.R.drawable.notification_bg)
  14.                 }
  15.      }
  16. }
Info
  1. onNewToken will be called when device token is generated. Use the API PSNotification.sendDeviceToken(s) to send the token to Zoho PageSense.
  2. onMessageReceived will be called when a notification is received. Here, you will need to call the PSNotification.isFromPageSensePlatform(remoteMessage.getData()) API to check whether notification is from Pagesense or not. After that, you need to call API PSNotification.showNotification(remoteMessage.getData(), com.zoho.pagesense.android.R.drawable.notification_bg); by sending the data and notification icon.

Permissions required for run-time:

In Android 13 and above, it is mandatory to add POST_NOTIFICATIONS permissions in the AndroidManifest.xml file and request runtime permissions to post notifications. For more information, refer to this Android developer document. 

In Android 12 and above, the below permissions should be enabled to process the call and snooze buttons inside notifications.
  1. <uses-permission android:name="android.permission.CALL_PHONE"/>
  2. <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> 
We hope this documentation helps make the process easy for you. Please feel free to reach out to us anytime by dropping an email to support@zohopagesense.com if you need more explanation or have any questions.