Callbacks and Delegates
FSOnReadyListener
FSOnReadyListener
can be used to get a callback when a session has started or resumed.
This is useful for getting the current session ID or session URL as FS.getCurrentSession
and FS.getCurrentSessionURL
will return null when there is no active session.
The listener can be set with FS.setReadyListener
(or removed by passing in null).
Method | Description |
---|---|
onReady(FSSessionData sessionData) | Called when the session has initialized and will begin or resume capturing. |
FSStatusListener
Since 1.47
FSStatusListener
can be used to get callbacks for a greater variety of events including
disabled session status and SDK errors.
Status listeners can be registered and unregistered with FS.registerStatusListener
and FS.unregisterStatusListener
respectively. Unlike FSOnReadyListeners, you can
have multiple FSStatusListeners registered concurrently.
Method | Description |
---|---|
onSession(FSSessionData sessionData) | Called when the session has initialized and will begin or resume capturing. This is equivalent to FSOnReadyListener#onReady . |
onSessionDisabled(FSReason reason) | Called when initialization has completed but FS will not begin capturing due to the session being disabled. |
onFSError(FSReason error) | Called when the SDK encounters an unrecoverable error and will cease or not begin to attempt capturing. |
onFSDisabled(FSReason reason) | Called when the SDK is disabled. This may be due to an incompatible device or OS version or due to FS not being instrumented. |
For convenience, a DefaultFSStatusListener
is provided that has empty implementations of each
callback method in the interface that you may extend and only have to implement the callbacks
you are interested in.
Additional Information
- Java
- Kotlin
public static void FS.setReadyListener(FSOnReadyListener listener);
public static void FS.registerStatusListener(FSStatusListener listener);
public static void FS.unregisterStatusListener(FSStatusListener listener);
public interface FSOnReadyListener {
@UiThread
void onReady(FSSessionData sessionData);
}
public interface FSStatusListener {
@UiThread
void onSession(FSSessionData sessionData);
@UiThread
void onSessionDisabled(FSReason reason);
@UiThread
void onFSError(FSReason error);
@UiThread
void onFSDisabled(FSReason reason);
}
Create and set an FSOnReadyListener for an Application that logs the session playback URL
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
FS.setReadyListener(new FSSessionReadyListener());
}
private static class FSSessionReadyListener implements FSOnReadyListener {
@Override
public void onReady(FSSessionData sessionData) {
Log.d("Fullstory", "Session URL is: " + sessionData.getCurrentSessionURL());
}
}
}
Register an FSStatusListener that logs status information
class MainActivity extends AppCompatActivity {
private final FSStatusListener listener = new StatusListener();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FS.registerStatusListener(listener);
}
@Override
protected void onDestroy() {
super.onDestroy();
FS.unregisterStatusListener(listener);
}
private static class StatusListener extends DefaultFSStatusListener {
@Override
public void onSession(FSSessionData sessionData) {
Log.d("Fullstory", "FS session URL:" + sessionData.getCurrentSessionURL());
}
@Override
public void onSessionDisabled(FSReason reason) {
Log.d("Fullstory", "Session disabled (" + reason.getCode() + "): " + reason.getMessage());
}
@Override
public void onFSError(FSReason error) {
Log.d("Fullstory", "FS Error (" + error.getCode() + "): " + error.getMessage());
}
@Override
public void onFSDisabled(FSReason reason) {
Log.d("Fullstory", "FS disabled (" + reason.getCode() + "): " + reason.getMessage());
}
}
}
fun FS.setReadyListener(listener: FSOnReadyListener?)
fun FS.registerStatusListener(listener: FSStatusListener)
fun FS.unregisterStatusListener(listener: FSStatusListener)
interface FSOnReadyListener {
@UiThread
fun onReady(sessionData: FSSessionData): Unit
}
interface FSStatusListener {
@UiThread
fun onSession(sessionData: FSSessionData);
@UiThread
fun onSessionDisabled(reason: FSReason);
@UiThread
fun onFSError(error: FSReason);
@UiThread
fun onFSDisabled(reason: FSReason);
}
Create and set an FSOnReadyListener for an Application that logs the session playback URL
class App : Application() {
override fun onCreate() {
super.onCreate()
FS.setReadyListener(FSSessionReadyListener())
}
private class FSSessionReadyListener : FSOnReadyListener {
override fun onReady(sessionData: FSSessionData) {
Log.d("Fullstory", "Session URL is: ${sessionData.currentSessionURL}")
}
}
}
Register an FSStatusListener that logs status information
class MainActivity : AppCompatActivity() {
private val listener = StatusListener()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FS.registerStatusListener(listener)
}
override fun onDestroy() {
super.onDestroy()
FS.unregisterStatusListener(listener)
}
private class StatusListener : DefaultFSStatusListener() {
override fun onSession(sessionData: FSSessionData) {
Log.d("Fullstory", "FS session URL: ${sessionData.currentSessionURL}")
}
override fun onSessionDisabled(reason: FSReason) {
Log.d("Fullstory", "Session disabled (${reason.code}): ${reason.message}")
}
override fun onFSError(error: FSReason) {
Log.d("Fullstory", "FS Error (${error.code}): ${error.message}")
}
override fun onFSDisabled(reason: FSReason) {
Log.d("Fullstory", "FS disabled (${reason.code}): ${reason.message}")
}
}
}