public interface

PushNotifications

com.glia.androidsdk.fcm.PushNotifications

Class Overview

Class responsible for handling FCM token and push messages.

Summary

Nested Classes
class PushNotifications.Events Push notification events  
interface PushNotifications.PushNotificationsEvent<T>  
Public Methods
abstract Set<PushNotificationEvent> getPushEvents()
Returns push notification events that the SDK is subscribed to.
abstract String getToken()
Returns the currently active token.
abstract GliaPushMessage handleOnMainActivityCreate(Bundle bundle)
Should be called when the main application activity is created.
abstract <T> void off(PushNotificationsEvent<T> event, Consumer<T> listener)
This method allows the removal of event listeners from the PushNotificationHandler.
abstract <T> void on(PushNotificationsEvent<T> event, Consumer<T> listener)
This method allows registration of event listeners for PushNotificationHandler.
abstract void onNewMessage(RemoteMessage message)
Should be called when a new remote message is received from the Firebase Cloud Messaging framework.
abstract void subscribeTo(Context context, Collection<PushNotificationType> types)
Allows to configure the push notifications that the SDK will subscribe to.
abstract void subscribeTo(Collection<PushNotificationEvent> events)
Allows to configure the push notifications that the SDK will subscribe to.
abstract void updateFcmToken(String newFcmToken)
This method should be called when a new token is generated by Firebase Cloud Messaging framework.

Public Methods

public abstract Set<PushNotificationEvent> getPushEvents ()

Returns push notification events that the SDK is subscribed to.

Returns

public abstract String getToken ()

Returns the currently active token.

Returns
  • FCM token.

public abstract GliaPushMessage handleOnMainActivityCreate (Bundle bundle)

Should be called when the main application activity is created.

Usage example:

 
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         ...

         GliaPushMessage push = Glia.getPushNotifications()
                 .handleOnMainActivityCreate(getIntent().getExtras());

         if (push != null && push.getType() == GliaPushMessage.PushType.CHAT_MESSAGE) {
             // handle the opening of the push notification
         }
     }
 
 

Parameters
bundle - A mapping from String keys got from the main activity intent
Returns
  • GliaPushMessage if the main activity is opened by clicking on the notification or null if not.

public abstract void off (PushNotificationsEvent<T> event, Consumer<T> listener)

This method allows the removal of event listeners from the PushNotificationHandler.

If an event listener is removed while the PushNotificationHandler is processing an event, it is not triggered with the current event.

Calling off with arguments which do not identify any currently registered listener has no effect.

Parameters
event - One of PushNotifications.Events
listener - Event listener to remove

public abstract void on (PushNotificationsEvent<T> event, Consumer<T> listener)

This method allows registration of event listeners for PushNotificationHandler.

If a listener is added while the PushNotificationHandler is processing an event, it is not triggered with the current event.

If multiple identical listeners are registered on the same event type the duplicate instances are discarded. They do not cause the listener to be called twice and do not need to be removed with the removeEventListener method.

Parameters
event - One of PushNotifications.Events
listener - Event listener to register

public abstract void onNewMessage (RemoteMessage message)

Should be called when a new remote message is received from the Firebase Cloud Messaging framework.

You should use this method only if you have your own FCM service.

Parameters
message - New FCM message
See Also

public abstract void subscribeTo (Context context, Collection<PushNotificationType> types)

Allows to configure the push notifications that the SDK will subscribe to.

The same as the subscribeTo(Collection) but allows to set the push notifications type with default messages:

  • com.glia.androidsdk.R.string#glia_webhook_event_start
  • com.glia.androidsdk.R.string#glia_webhook_event_end
  • com.glia.androidsdk.R.string#glia_webhook_event_failed
  • com.glia.androidsdk.R.string#glia_webhook_event_message
  • com.glia.androidsdk.R.string#glia_webhook_event_transfer

Parameters
context - Application context * @param types - Collection of PushNotificationType to subscribe to

public abstract void subscribeTo (Collection<PushNotificationEvent> events)

Allows to configure the push notifications that the SDK will subscribe to.

If the notifications aren't configured, by default the SDK subscribes to the following push notifications:

Ensure that you call this method as early as possible, preferably in the implementation of the android.app.Application, and definitely before starting an engagement. Calling this method after creating an engagement will only enable push notifications for subsequent engagements.

Parameters
events - Collection of PushNotificationEvent to subscribe to

public abstract void updateFcmToken (String newFcmToken)

This method should be called when a new token is generated by Firebase Cloud Messaging framework.

You should use this method only if you have your own FCM service.

Parameters
newFcmToken - New FCM token
See Also