showNotification

This method displays the custom view when a user is sent a push notification.

A Push Notification is a message that pops up on a mobile device. App publishers can send them at any time; users don't have to be in the app or using their devices to receive them.

There are various ways in which a Push Notification can be viewed: Standard and Extended. Standard provides a heading and image only; Extended provides a preview of the content.

The showNotification method will present the notification with the information passed in the parameters.

We can get two types of response - one from GCM and other from FCM. For GCM we get a bundle in response then pass null as map, and for FCM we get a map in response then pass null as bundle.

This feature gives you backwards compatibility for existing GCM users.

Method Signature

void showNotification(Bundle gcmData, Map<String, String> fcmData, int imageId)

To add the method

  1. Open your project.
  2. Open app > src > main > java > package name > MyFirebaseMessagingService.
  3. Add the method code: Method Code

Arguments

These are the arguments that define the method.

Name Type Mandatory Description
gcmData Bundle Mandatory Bundle is the GCM data that you receive in MyFirebaseMessagingService. It is null when the message is received from FCM.
fcmData Map Mandatory Map is the FCM data that you receive in MyFirebaseMessagingService. It is null when the message is received from GCM.
imageId Integer Optional The image id which is in drawable folder,Passed imageId will be used as notification icon.

Sample Code

if(Analytics.getInstance(this).pushNotificationWasSentFromHurree(bundle)){
    imageId = R.drawable.ic_launcher;
    /*
    * @bundle is the data you get from server for push notifictaion.
    *
    * @imageId is the image id which is in drawable folder,Passed imageId will be used as notification icon.
    * eg. imageId = R.drawable.ic_launcher;
    **/
    Analytics.getInstance(this).showNotification(null, fcmData, imageId);
}

results matching ""

    No results matching ""