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

PropertiesTypeDescription
applicationContextContextThe application context for WebexConnect.
instanceWebexConnectThe singleton instance of WebexConnect.

Properties

PropertiesTypeDescription
deviceProfileDeviceProfileHolds the current device profile information, if available.
isRegisteredBooleanIt indicates whether the device or user has been registered.
isStartedBooleanIt indicates whether the Webex Connect has been started.
sdkVersionStringThe version of the SDK is being used.

Following are the methods of WebexConnect.

MethodDescription
startupStarts up WebexConnect.
shutdownUsed to cleanup internal resources used by the SDK.
registerModuleRegisters one or multiple ConnectModules.
registerRegisters the provided device profile with the Webex Connect platform.
unregisterUnregisters the current device profile from the Webex Connect platform.
updateProfileParamUpdates a parameter of the current device profile within the Webex Connect platform.
removeProfileParamRemoves a parameter of the current device profile from the Webex Connect platform.
publishEventInvoke publishEvent to publish your custom events info to the Webex Connect platform.
setLoggerSets the logger.
setSecurityTokenUsed to specify a Security Token that the SDK will pass to the Webex Connect platform for all user-centric API requests.
registerSecurityTokenListenerRegisters a listener to handle security token exception.
unregisterSecurityTokenListenerUnregisters 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

ParameterTypeDescription
callbackWebexConnectResponseHandlerA 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

ParametersTypeDescription
configConfigThe configuration for startup.
callbackWebexConnectResponseHandlerA 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

ParameterTypeDescription
callbackWebexConnectResponseHandlerA 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)

ParametersTypeDescription
modulesConnectModuleThe ConnectModule to register.

register

Registers the provided device profile with the Webex Connect platform.

Syntax: abstract fun register( deviceProfile: DeviceProfile, callback: WebexConnectJsonResponseHandler)

ParametersTypeDescription
deviceProfileDeviceProfileThe device profile used for registration.
callbackWebexConnectJsonResponseHandlerA 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

ParameterTypeDescription
callbackWebexConnectJsonResponseHandlerA 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

ParameterTypeDescription
paramDeviceProfileParamThe DeviceProfileParam specifies which part of the profile to update.
valuestringThe new value to update the profile with.
callbackWebexConnectJsonResponseHandlerA 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)

ParametersTypeDescription
paramDeviceProfileParamThe DeviceProfileParam specifies which part of the profile to remove.
callbackWebexConnectJsonResponseHandlerA 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)

ParameterTypeDescription
eventJSONObjectThe JSONObject that contains data to be published with the event.
callbackWebexConnectJsonResponseHandlerA 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

ParameterTypeDescription
loggerLoggerA 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

ParameterTypeDescription
tokenStringThe security token is a String.

registerSecurityTokenListener

Registers a listener to handle security token exception.

Syntax: abstract fun registerListener(listener: WebexConnectResponseHandler)

ParametersTypeDescription
listenerWebexConnectResponseHandlerA 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

ParameterTypeDescription
listenerWebexConnectResponseHandlerThe WebexConnectResponseHandler to unregister.