public abstract class

SosAvailability

extends Object
java.lang.Object
   ↳ com.salesforce.android.sos.api.SosAvailability

Class Overview

API used for monitoring the SOS system for agent availability updates. Availability checks should usually follow this pattern:

  1. Call addListener(Listener) to add a listener object (typically an activity).
  2. Call startPolling(Context, String, String, String) to start polling for availability changes.
  3. React to calls to onSosAvailabilityChange(Status) to enable or disable SOS-related functionality.
  4. When the listener object is no longer needed, call removeListener(Listener) (e.g. in the activity's onDestroy() method.)
  5. Call stopPolling() if you no longer need to monitor SOS availability.

Usage Example

  
    public class MyActivity extends Activity implements SosAvailability.Listener {

      @Override
      public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Add ourselves as an availability listener.
        SosAvailability.addListener(this);

        // Update the UI based on the last known availability status, if any.
        updateAvailability(SosAvailability.getStatus());

        // Start polling to receive any change in the status.
        if (!SosAvailability.isPolling()) {
          SosAvailability.startPolling(this, organizationId, deploymentId, liveAgentPod);
        }
      }

      @Override
      public void onDestroy () {
        super.onDestroy();
        // Always makes sure to remove the listener.
        SosAvailability.removeListener(this);

        // Stop polling if appropriate. Don't do this if you want polling to continue in the
        // background.
        SosAvailability.stopPolling();
      }

      @Override
      public void onSosAvailabilityChange (SosAvailability.Status status) {
        updateAvailability(status);
      }

      private void updateAvailability (SosAvailability.Status status) {
        // Update the UI to reflect the availability status here.
      }
    }
  
 

Summary

Nested Classes
interface SosAvailability.Listener The Listener interface is used to receive updates about the SOS availability status. 
enum SosAvailability.Status Enumerates the possible availability statuses for SOS. 
Public Constructors
SosAvailability()
Public Methods
static void addListener(SosAvailability.Listener listener)
Adds a Listener instance to listen for availability status changes.
static SosAvailability.Status getStatus()
Return the result of the most recent poll request.
static boolean isPolling()
Checks if the SDK is current polling for availability status.
static void removeListener(SosAvailability.Listener listener)
Removes a previously added Listener instance.
static void startPolling(Context context, String organizationId, String deploymentId, String liveAgentPod)
Starts polling the availability endpoint with the given information.
static void stopPolling()
Stops the polling explicitly.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SosAvailability ()

Public Methods

public static void addListener (SosAvailability.Listener listener)

Adds a Listener instance to listen for availability status changes. Listeners should be removed when they no longer need to respond to availability changes.

Parameters
listener The Listener instance to add.

public static SosAvailability.Status getStatus ()

Return the result of the most recent poll request.

Returns
  • The last-known availability status of SOS.

public static boolean isPolling ()

Checks if the SDK is current polling for availability status. This is true in between calls to startPolling(Context, String, String, String) and stopPolling(), and false otherwise.

Returns
  • True if the SDK has a poll request outstanding or scheduled, false otherwise.

public static void removeListener (SosAvailability.Listener listener)

Removes a previously added Listener instance.

Parameters
listener The listener to remove.

public static void startPolling (Context context, String organizationId, String deploymentId, String liveAgentPod)

Starts polling the availability endpoint with the given information. This method must be called in order to kickstart the process which will trigger the SosAvailability.Listener instances when the availability status of the SOS system changes. This method should only be called once; multiple calls will cancel and restart any in-progress availability checks.

Parameters
context A context to use for polling.
organizationId The Salesforce Organization ID for your company.
deploymentId The Salesforce Deployment ID identifying the deployment queue to check.
liveAgentPod The live agent server to use.

public static void stopPolling ()

Stops the polling explicitly. This should be called when you no longer need to know about the SOS availability status in order to release resources associated with the polling mechanism. Note that polling will be stopped automatically when a session is started. This method is idempotent.