WebexConnect
The main interface for interacting with the WebexConnect service, including methods for startup, shutdown, registration, and profile management.
The WebexConnect interface provides methods to initialize the SDK and manage user registration. When integrating the SDK into your app, it is mandatory to use this class to initialize the SDK before any other features are used.
Companion
The companion object for WebexConnect.
Companion Properties
Properties | Type | Description |
---|---|---|
applicationContext | Context | The application context for WebexConnect. |
instance | WebexConnect | The singleton instance of WebexConnect. |
Properties
Properties | Type | Description |
---|---|---|
deviceProfile | DeviceProfile | Holds the current device profile information, if available. |
isRegistered | Boolean | It indicates whether the device or user has been registered. |
isStarted | Boolean | It indicates whether the Webex Connect has been started. |
sdkVersion | String | The version of the SDK is being used. |
Following are the methods of WebexConnect.
Method | Description |
---|---|
startup | Starts up WebexConnect. |
shutdown | Used to cleanup internal resources used by the SDK. |
registerModule | Registers one or multiple ConnectModules. |
register | Registers the provided device profile with the Webex Connect platform. |
unregister | Unregisters the current device profile from the Webex Connect platform. |
updateProfileParam | Updates a parameter of the current device profile within the Webex Connect platform. |
removeProfileParam | Removes a parameter of the current device profile from the Webex Connect platform. |
publishEvent | Invoke publishEvent to publish your custom events info to the Webex Connect platform. |
setLogger | Sets the logger. |
setSecurityToken | Used to specify a Security Token that the SDK will pass to the Webex Connect platform for all user-centric API requests. |
registerSecurityTokenListener | Registers a listener to handle security token exception. |
unregisterSecurityTokenListener | Unregisters a previously registered listener for security token exception. |
startup(callback)
Starts up WebexConnect. Initializes the SDK by reading configuration data from the application manifest. These methods perform all of their work on a background thread. Once startup is complete, or if an error occurs, the callback will be invoked to report the result of the operation. Please note that the callback is invoked on the main thread, as such you should not perform any long-running operation within the callback.
Syntax: abstract fun startup(callback: WebexConnectResponseHandler)
Parameters
Parameter | Type | Description |
---|---|---|
callback | WebexConnectResponseHandler | A WebexConnectResponseHandler function is to be invoked upon startup completion. It will be called with any exception that occurred during startup (or null if none). |
Sample code
/ Initialize the WebexConnect instance
val webexConnect = WebexConnect.instance
// Check if the WebexConnect instance is not started
if (!webexConnect.isStarted) {
// Call the startup method of the WebexConnect instance
webexConnect.startup { exception ->
if (exception == null && webexConnect.isStarted) {
// Log the success message
Log.d("MyApplication", "WebexConnect SDK started successfully")
} else {
// Log the error message
Log.e("MyApplication", "WebexConnect SDK failed to start: ${exception.message}")
}
}
}
startup(config, callback)
Initializes the SDK by using the Config object "config" that is to be defined by the developer. These methods perform all of their work on a background thread. Once startup is complete, or if an error occurs, the callback will be invoked to report the result of the operation. Please note that the callback is invoked on the main thread, as such you should not perform any long-running operation within the callback.
Syntax: abstract fun startup(config: Config, callback: WebexConnectResponseHandler)
Parameters
Parameters | Type | Description |
---|---|---|
config | Config | The configuration for startup. |
callback | WebexConnectResponseHandler | A WebexConnectResponseHandler function is to be invoked upon startup completion. It will be called with any exception that occurred during startup (or null if none). |
Sample code to startup the SDK:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
WebexConnect.applicationContext = this
// Get the instance of WebexConnect
val webexConnect: WebexConnect = WebexConnect.instance
// Check if the WebexConnect instance is not started
if (!webexConnect.isStarted) {
// Call the startup method of the WebexConnect instance
val config = Config(appId, clientKey)
webexConnect.startup(config) { exception ->
if (exception == null) {
Log.d("MyApplication", "WebexConnect SDK started successfully")
} else {
Log.e("MyApplication", "WebexConnect SDK failed to start: ${exception.message}")
}
}
}
}
}
public class DemoApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize the Webex Connect SDK
WebexConnect webexConnect = WebexConnect.getInstance();
Config config = new Config(appId, clientKey, Environment.UK);
webexConnect.startup(config, exception ->
{
if (exception != null) {
Log.e("DemoApplication", "WebexConnect startup failed: " + exception.getMessage());
} else {
Log.i("DemoApplication", "WebexConnect startup successful");
}
return null;
});
}
}
shutdown()
Used to clean up internal resources used by the SDK. Invoking this method will stop all SDK features from functioning, In-app messages will no longer be received and Push notifications will no longer be handled.
Syntax:abstract fun shutdown(callback: WebexConnectResponseHandler)
Parameters
Parameter | Type | Description |
---|---|---|
callback | WebexConnectResponseHandler | A WebexConnectResponseHandler function is to be invoked upon shutdown completion. It will be called with any exception that occurred during shutdown (or null if none). |
Sample code to shutdown the SDK:
WebexConnect.instance.shutdown { exception ->
if (exception != null) {
Log.e("shutdown", "shutdown failed! Reason:$exception")
} else {
Log.d("shutdown", "shutdown Succeeded")
}
}
WebexConnect.getInstance().shutdown((exception) -> {
if (exception != null) {
Log.e("shutdown", "shutdown failed! Reason: " + exception.getMessage());
} else {
Log.d("shutdown", "shutdown Succeeded");
}
return null;
});
registerModule
Registers one or multiple ConnectModules.
Syntax: abstract fun registerModule(vararg modules: ConnectModule)
Parameters | Type | Description |
---|---|---|
modules | ConnectModule | The ConnectModule to register. |
register
Registers the provided device profile with the Webex Connect platform.
Syntax: abstract fun register( deviceProfile: DeviceProfile, callback: WebexConnectJsonResponseHandler)
Parameters | Type | Description |
---|---|---|
deviceProfile | DeviceProfile | The device profile used for registration. |
callback | WebexConnectJsonResponseHandler | A WebexConnectJsonResponseHandlerfunction is to be invoked upon registration completion. It will be called with a JSONObject object and any exception that occurred during registration (or null if none). |
val userId = "PROVIDE YOUR USERID"
val deviceProfile = DeviceProfile(DeviceProfile.defaultDeviceId, userId)
WebexConnect.instance.register(deviceProfile) { jsonObject, exception ->
if (exception != null) {
Log.e("Registration", "Registration failed! Reason: $exception")
} else {
Log.d("Registration", "Registration succeeded!")
}
}
String userId = "PROVIDE YOUR USERID";
DeviceProfile profile = new DeviceProfile(DeviceProfile.getDefaultDeviceId(), userId);
WebexConnect.getInstance().register(profile, (jsonObject, exception) -> {
if (exception != null) {
// Show the error message
Log.e("Registration", "Registration failed! Reason:" + exception);
return null;
} else {
Log.d("Registration", "Registration succeeded!");
}
return null;
});
val deviceProfile = DeviceProfile(DeviceProfile.defaultDeviceId)
WebexConnect.instance.register(deviceProfile) { jsonObject, exception ->
if (exception != null) {
Log.e("Registration", "Registration failed! Reason: $exception")
} else {
Log.d("Registration", "Registration succeeded! $jsonObject")
}
}
DeviceProfile profile = new DeviceProfile(DeviceProfile.getDefaultDeviceId());
// Call the register method
WebexConnect.getInstance().register(profile, (jsonObject, exception) -> {
if (exception != null) {
// Show the error message
Log.e("Registration", "Registration failed! Reason:" + exception);
return null;
} else {
Log.d("Registration", "Registration succeeded!");
}
return null;
});
unregister
Unregisters the current device profile from the Webex Connect platform. On successful completion, Push and In-App Messages will no longer be received on the device.
Syntax: abstract fun unregister(callback: WebexConnectJsonResponseHandler)
Parameters
Parameter | Type | Description |
---|---|---|
callback | WebexConnectJsonResponseHandler | A WebexConnectJsonResponseHandler function is to be invoked upon un-registration completion. It will be called with a JSONObject object and any exception that occurred during un-registration (or null if none). |
WebexConnect.instance.unregister { responseJson, exception ->
if (exception != null) {
Log.e("unregister", "unRegistration failed! Reason:$exception")
} else {
Log.d("unregister", "unRegistration Succeeded")
}
}
WebexConnect.getInstance().unregister((jsonObject, exception) -> {
if (exception != null) {
Log.e("unregister", "unregistration failed! Reason: " + exception.getMessage());
} else {
Log.i("unregister", "unregistration Succeeded");
}
return null;
});
updateProfileParam
Updates a parameter of the current device profile within the Webex Connect platform.
Syntax: abstract fun updateProfileParam(param: DeviceProfileParam, value: String, callback: WebexConnectJsonResponseHandler)
Parameters
Parameter | Type | Description |
---|---|---|
param | DeviceProfileParam | The DeviceProfileParam specifies which part of the profile to update. |
value | string | The new value to update the profile with. |
callback | WebexConnectJsonResponseHandler | A WebexConnectJsonResponseHandler function is to be invoked upon update completion. It will be called with a JSONObject object and any exception that occurred during the update (or null if none). |
Sample Code
WebexConnect.instance.updateProfileParam(DeviceProfileParam.USER_ID,customerIdValue) { jsonObject, exception ->
if (exception != null) {
Log.e(
"updateProfileParam",
" updateProfileParam for userId failed! Reason: $exception.toString()"
)
} else {
Log.d("updateProfileParam", "updateProfileParam for userId Succeeded")
}
}
WebexConnect.getInstance().updateProfileParam(DeviceProfileParam.USER_ID,userIdValue, (jsonObject, exception) -> {
if (exception != null) {
Log.e("updateProfileParam", "updateProfileParam for userId failed! Reason: " + exception.getMessage());
} else {
Log.i("updateProfileParam", "updateProfileParam for userId Succeeded");
}
return null;
});
WebexConnect.instance.updateProfileParam(DeviceProfileParam.CUSTOMER_ID,customerIdValue) { jsonObject, exception ->
if (exception != null) {
Log.e(
"updateProfileParam",
" updateProfileParam for customerId failed! Reason: $exception"
)
} else {
Log.d("updateProfileParam", "updateProfileParam for customerId Succeeded")
}
}
WebexConnect.getInstance().updateProfileParam(DeviceProfileParam.CUSTOMER_ID,customerIdValue, (jsonObject, exception) -> {
if (exception != null) {
Log.e("updateProfileParam", "updateProfileParam for customerId failed! Reason: " + exception.getMessage());
} else {
Log.i("updateProfileParam", "updateProfileParam for customerId Succeeded");
}
return null;
});
removeProfileParam
Removes the specified parameter of the current device profile from the Webex Connect platform.
Syntax:abstract fun removeProfileParam(param: DeviceProfileParam, callback: WebexConnectJsonResponseHandler)
Parameters | Type | Description |
---|---|---|
param | DeviceProfileParam | The DeviceProfileParam specifies which part of the profile to remove. |
callback | WebexConnectJsonResponseHandler | A WebexConnectJsonResponseHandler function is to be invoked upon removal completion. It will be called with a JSONObject object and any exception that occurred during the removal (or null if none). |
Sample code
WebexConnect.instance.removeProfileParam(DeviceProfileParam.USER_ID) { jsonObject, exception ->
if (exception != null) {
Log.e(
"RemoveProfileParam"," removeProfileParam for userid failed! Reason: $exception.toString()")
} else {
Log.d("RemoveProfileParam", "removeProfileParam for userId Succeeded")
}
}
WebexConnect.getInstance().removeProfileParam(DeviceProfileParam.USER_ID, (jsonObject, exception) -> {
if (exception != null) {
Log.e("removeProfileParam", "removeProfileParam for userId Failed! Reason: " + exception.getMessage());
} else {
Log.i("removeProfileParam", "removeProfileParam for userId Succeeded");
}
return null;
});
WebexConnect.instance.removeProfileParam(DeviceProfileParam.CUSTOMER_ID) { jsonObject, exception ->
if (exception != null) {
Log.e(
"RemoveProfileParam",
" removeProfileParam for customerId failed! Reason: $exception.toString()"
)
} else {
Log.d("RemoveProfileParam", "removeProfileParam for customerId Succeeded")
}
}
WebexConnect.getInstance().removeProfileParam(DeviceProfileParam.CUSTOMER_ID, (jsonObject, exception) -> {
if (exception != null) {
Log.e("removeProfileParam", "removeProfileParam for customerId failed! Reason: " + exception.getMessage());
} else {
Log.i("removeProfileParam", "removeProfileParam for customerId Succeeded");
}
return null;
});
publishEvent
Publishes an event with the provided JSONObject data.
Syntax:abstract fun publishEvent(event: JSONObject, callback: WebexConnectJsonResponseHandler)
Parameter | Type | Description |
---|---|---|
event | JSONObject | The JSONObject that contains data to be published with the event. |
callback | WebexConnectJsonResponseHandler | A WebexConnectJsonResponseHandleris function to be invoked upon event publication completion. It will be called with the same JSONObject object and any exception that occurred during publication (or null if none). |
setLogger
Sets the logger.
Syntax: abstract fun setLogger(logger: Logger)
Parameters
Parameter | Type | Description |
---|---|---|
logger | Logger | A Logger instance is to be used for logging. |
setSecurityToken
Used to specify a Security Token that the SDK will pass to the Webex Connect platform for all user-centric API requests. The platform will validate the token before processing requests.
Syntax: abstract fun setSecurityToken(token: String)
Parameters
Parameter | Type | Description |
---|---|---|
token | String | The security token is a String. |
registerSecurityTokenListener
Registers a listener to handle security token exception.
Syntax: abstract fun registerListener(listener: WebexConnectResponseHandler)
Parameters | Type | Description |
---|---|---|
listener | WebexConnectResponseHandler | A WebexConnectResponseHandler to register, and it will be invoked when a security token exception occurs. |
Sample code to registerSecurityTokenListener:
WebexConnect.instance.registerSecurityTokenListener { exception ->
if (exception != null) {
when (exception.errorCode) {
ErrorCode.TOKEN_EXPIRED ,ErrorCode.TOKEN_REQUIRED,ErrorCode.TOKEN_INVALID-> {
// Generate the token and pass back to the SDK
// via WebexConnect.instance.setSecurityToken(generatedToken);
}
else -> {}
}
}
}
WebexConnect.getInstance().registerSecurityTokenListener(exception -> {
if (exception.getErrorCode() != null) {
switch (exception.getErrorCode()) {
case TOKEN_INVALID:
// Token is invalid, regenerate
case TOKEN_EXPIRED:
// Token has expired, regenerate
case TOKEN_REQUIRED:
// Token is required, generate
// Generate the token and pass back to the SDK
// via WebexConnect.Companion.getInstance().setSecurityToken(generatedToken);
}
}
return null;
});
unregisterSecurityTokenListener
Unregisters a previously registered listener for security token exception.
Syntax: abstract fun unregisterListener(listener: WebexConnectResponseHandler)
Parameters
Parameter | Type | Description |
---|---|---|
listener | WebexConnectResponseHandler | The WebexConnectResponseHandler to unregister. |
Updated about 1 month ago