public final class

Sos

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

Class Overview

The main API to interface with the session lifecycle.

Summary

Nested Classes
class Sos.SessionBuilder SessionBuilder is used to aid in the construction of an SOS session. 
class Sos.SessionExistsException Thrown when caller attempts to start an SOS session while one already exists. 
Public Methods
static boolean addAVListener(SosAVListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addConnectionListener(SosConnectionListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addHoldListener(SosHoldListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addListener(SosListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addMaskingListener(SosMaskingListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addNetworkTestListener(SosNetworkTestListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static boolean addShareTypeListener(SosShareTypeListener listener)
Adds the given listener to all current and future SOS sessions until it is removed.
static void captureExtra(Toast toast)
Manually instruct the SOS framework to add a toast to the captured video stream sent to the agent.
static void captureExtra(Dialog dialog)
Manually instruct the SOS framework to add a dialog to the captured video stream sent to the agent.
static void endSession(boolean showPrompt)
Ends the currently active SOS session.
static SosConfiguration getConfiguration()
Retrieve the configuration that was used to start the session.
static SosHoldState getHoldState()
Get the current Hold state of the session.
static String getId()
Retrieves the identifier for the current SOS session, if any.
static SosShareType getInitialShareType()
Get the initial share type for the session based on your SosConfiguration and the presence of camera hardware on the end-user's device.
static SosOptions getOptions()
Retrieve the options that were used to start the session.
static SosState getState()
Retrieve the configuration that was used to start the session.
static String getVersion()
Returns the SemVer version string for the SDK.
static void hideKeyboard()
Tells the SOS framework to hide any currently displayed keyboard bitmap.
static boolean isScreenSharingEnabled()
Get whether screen sharing is currently enabled.
static boolean isSessionActive()
Checks to see if there is an active SOS session.
static boolean removeAVListener(SosAVListener listener)
Removes the specified listener object.
static boolean removeConnectionListener(SosConnectionListener listener)
Removes the specified listener object.
static boolean removeHoldListener(SosHoldListener listener)
Removes the specified listener object.
static boolean removeListener(SosListener listener)
Removes the specified listener object.
static boolean removeMaskingListener(SosMaskingListener listener)
Removes the specified listener object.
static boolean removeNetworkTestListener(SosNetworkTestListener listener)
Removes the specified listener object.
static boolean removeShareTypeListener(SosShareTypeListener listener)
Removes the specified listener object.
static Sos.SessionBuilder session(SosOptions options)
Build a new SOS session.
static void setAudioEnabled(boolean enabled)
Mute/unmute the customer audio.
static void setPosition(int x, int y)
Set the position of the Agent's video view in the Service Cloud Console.
static void setScreenSharingEnabled(boolean enabled)
Turn on/off screen sharing.
static void setSessionPaused(boolean paused)
Pause/un-pause the session.
static void setShareType(SosShareType shareType)
Transition from the current share type to another.
static void setTwoWayVideoEnabled(boolean enabled)
Turn on/off two-way video.
static void showKeyboard(Rect position)
Tell the SOS framework to display a bitmap representing a keyboard on the screen.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static boolean addAVListener (SosAVListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosAVListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeAVListener(SosAVListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener the listener to add.
Returns
  • True if the listener was added.

public static boolean addConnectionListener (SosConnectionListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosConnectionListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeConnectionListener(SosConnectionListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener The listener to add.
Returns
  • True if the listener was added.

public static boolean addHoldListener (SosHoldListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosHoldListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeHoldListener(SosHoldListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener the listener to add.
Returns
  • True if the listener was added.

public static boolean addListener (SosListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeListener(SosListener) when you no longer wish to receive events regarding SOS sessions. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener The listener to add.
Returns
  • True if the listener was added.

public static boolean addMaskingListener (SosMaskingListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosMaskingListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeMaskingListener(SosMaskingListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener The listener to add.
Returns
  • True if the listener was added.

public static boolean addNetworkTestListener (SosNetworkTestListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosNetworkTestListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeNetworkTestListener(SosNetworkTestListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener the listener to add.
Returns
  • True if the listener was added.

public static boolean addShareTypeListener (SosShareTypeListener listener)

Adds the given listener to all current and future SOS sessions until it is removed. Listeners may only be added once, multiple calls for a given listener will not add the listener multiple times.

See SosShareTypeListener for usage instructions.

Note that this listener instance is strongly referenced, and thus must be explicitly removed by calling removeShareTypeListener(SosShareTypeListener) when you no longer wish to receive events. Failure to remove a listener can result in a memory leak in your application.

Parameters
listener the listener to add.
Returns
  • True if the listener was added.

public static void captureExtra (Toast toast)

Manually instruct the SOS framework to add a toast to the captured video stream sent to the agent.

Toasts present to the user will not be captured by default, and must be explicitly passed to the framework via this method in order to be drawn into the captured video.

Note that the Toast must not be null.

Parameters
toast The Toast instance that should be included in the captured video stream.

public static void captureExtra (Dialog dialog)

Manually instruct the SOS framework to add a dialog to the captured video stream sent to the agent. Dialogs present to the user will not be captured by default, and must be explicitly passed to the framework via this method in order to be drawn into the captured video.

Notes

The Dialog must not be null

A common pitfall is to create your dialog and immediately pass reference to Sos. In some cases this may not work. For example:

   
     MyDialogFragment myDialog = new MyDialogFragment();
     myDialog.show(getFragmentManager());
     Sos.captureExtra(myDialog.getDialog());
   
 

Will not work. Either getDialog will return null or the view will not be ready yet. In cases such as this it is recommended you wait until the DialogFragment is created to pass reference. For example:

   
     // From within `MyDialogFragment`
     @Override
     public Dialog onCreateDialog (Bundle savedInstanceState) {
       Dialog dialog = super.onCreateDialog(savedInstanceState);
       Sos.captureExtra(dialog);
       return dialog;
     }
   
 

Properly dispose of your Dialog if the Activity stops

You will observe odd behavior if you allow your Dialog to leak the app window.

A common case this comes up is when in a call, if you rotate your device, the dialog disappears, but the agent continues to see the dialog and there is seemingly no way to get rid of it. Check your device logs and ensure that you are not leaking the window. You will see something like

   
     android.view.WindowLeaked: Activity com.yourpackage.YourActivity has leaked window com.android.internal...
   
 
Generally, this means you did not dismiss your dialog when you rotated your device, and since Sos holds a reference to it, bad things happen. The most common fix for this problem is to dismiss the dialog when your activity stops. Or, use a DialogFragment instead.

Parameters
dialog The dialog instance that should be included in the captured video stream.

public static void endSession (boolean showPrompt)

Ends the currently active SOS session. If there is no active session then this method will have no effect.

Parameters
showPrompt Used to determine whether or not the user should be prompted to confirm before ending the session. If false is passed the session will simply end without prompting the user.

public static SosConfiguration getConfiguration ()

Retrieve the configuration that was used to start the session.

Returns
  • The configuration used to start the session, or null if there is no active session.

public static SosHoldState getHoldState ()

Get the current Hold state of the session.

Returns
  • The current hold state, or null if there is no active session.

public static String getId ()

Retrieves the identifier for the current SOS session, if any.

Returns
  • The identifier for the session. The identifier is only available once the state has been changed to WaitingForAgent, prior to this the returned id will be null.

public static SosShareType getInitialShareType ()

Get the initial share type for the session based on your SosConfiguration and the presence of camera hardware on the end-user's device. For example, if your SosConfiguration has the default share type set to FrontFacingCamera but the user's device does not have a front camera, then the next available camera device will be chosen. If there are no camera devices present on the device, this method will return ScreenSharing. This method will return null unless the session has been started.

Returns
  • The session's most likely initial share type, or null if the session has not been started.

public static SosOptions getOptions ()

Retrieve the options that were used to start the session.

Returns
  • The options used to start the session, or null if there is no active session.

public static SosState getState ()

Retrieve the configuration that was used to start the session.

Returns
  • The configuration used to start the session.

public static String getVersion ()

Returns the SemVer version string for the SDK.

Returns
  • String - SDK SemVer version string

public static void hideKeyboard ()

Tells the SOS framework to hide any currently displayed keyboard bitmap.

public static boolean isScreenSharingEnabled ()

Get whether screen sharing is currently enabled.

Returns
  • Whether screen sharing is currently enabled.

public static boolean isSessionActive ()

Checks to see if there is an active SOS session. An "active" session is one that has been started and has connected to the SOS Service, but is not yet ended.

Returns
  • True if there is an active session.

public static boolean removeAVListener (SosAVListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addAVListener(SosAVListener).

See SosAVListener for usage instructions.

Parameters
listener the listener to remove.
Returns
  • True if the listener object was removed.

public static boolean removeConnectionListener (SosConnectionListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addConnectionListener(SosConnectionListener).

See SosConnectionListener for usage instructions.

Parameters
listener The listener to remove.
Returns
  • True if the listener was removed.

public static boolean removeHoldListener (SosHoldListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addHoldListener(SosHoldListener).

See SosHoldListener for usage instructions.

Parameters
listener the listener to remove.
Returns
  • True if the listener object was removed.

public static boolean removeListener (SosListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addListener(SosListener).

Parameters
listener The listener to remove.
Returns
  • True if the listener was removed.

public static boolean removeMaskingListener (SosMaskingListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addMaskingListener(SosMaskingListener).

See SosMaskingListener for usage instructions.

Parameters
listener The listener to remove.
Returns
  • True if the listener was removed.

public static boolean removeNetworkTestListener (SosNetworkTestListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addNetworkTestListener(SosNetworkTestListener).

See SosNetworkTestListener for usage instructions.

Parameters
listener the listener to remove.
Returns
  • True if the listener object was removed.

public static boolean removeShareTypeListener (SosShareTypeListener listener)

Removes the specified listener object. Does nothing if the listener was not previously added with addShareTypeListener(SosShareTypeListener).

See SosShareTypeListener for usage instructions.

Parameters
listener the listener to remove.
Returns
  • True if the listener object was removed.

public static Sos.SessionBuilder session (SosOptions options)

Build a new SOS session.

A session may be started by calling the start(Activity) method after all of your desired parameters have been set.

Parameters
options The options for connecting the session.
Returns

public static void setAudioEnabled (boolean enabled)

Mute/unmute the customer audio.

Parameters
enabled whether or not the customer audio should be transmitted.

public static void setPosition (int x, int y)

Set the position of the Agent's video view in the Service Cloud Console.

NOTE: The coordinate value you pass here will move the center of the agent's video container in the Service Cloud Console to that point.

This is done to allow a custom UI with a different window size to look more aligned by being center aligned. e.g. A view on the phone that is 500dp * 500dp would be substantially larger than the agent window in the Service Cloud Console. They will look more in-line with each other of the center of the views are on the same point of the screen.

If you are keeping two views in-line with each other, the recommended way to call this method looks like
Sos.setPosition(myView.getWidth() / 2 + myView.getX(), myView.getHeight() / 2 + myView.getY());

If you simply want to move the agent window, you are free to do so however you please.

Parameters
x The center-based x-coordinate.
y The center-based y-coordinate.

public static void setScreenSharingEnabled (boolean enabled)

Turn on/off screen sharing. The default behavior of SOS is to enable screen sharing during a session. However screen sharing can be enabled/disabled at any time.

Parameters
enabled whether or not to capture and send the device screen over SOS.

public static void setSessionPaused (boolean paused)

Pause/un-pause the session. Pausing the session will halt the transmission of video and audio between the user and the agent.

Parameters
paused True if the session must be paused, false to un-pause the session.

public static void setShareType (SosShareType shareType)

Transition from the current share type to another.

Parameters
shareType The share type to transition to.
See Also

public static void setTwoWayVideoEnabled (boolean enabled)

Turn on/off two-way video. twoWayVideo(boolean) must be set to allow two-way video before starting the session.

Parameters
enabled whether or not to broadcast the customers camera rather than their phone screen.

public static void showKeyboard (Rect position)

Tell the SOS framework to display a bitmap representing a keyboard on the screen.

Parameters
position the area on the screen covered by the keyboard (in pixels). A value of null indicates that the keyboard covers the entire screen.