-
Notifications
You must be signed in to change notification settings - Fork 1
3. Connecting to CafeBazaar
Ali Nasrabadi edited this page Oct 28, 2025
·
4 revisions
Before you can use the Referrer SDK, you must establish a connection to the CafeBazaar app using the following steps:
- Call the
getClient()method to create an instance ofReferrerClientclass. - Call the
startConnection()to establish a connection to CafeBazaar. - The
startConnection()method is asynchronous, so you must overrideClientStateListenerto receive a callback afterstartConnection()completes. - Override the
onReady()method to start your logic for getting referrer content after the referrer client gets connected. - Override the
onError()method to handle any connection issue.
Note: The startConnection() has to be called off the main thread otherwise it will throw an exception.
The following code demonstrates how to start a connection to the CafeBazaar app:
private val referrerClient: ReferrerClient by lazy { ReferrerClient.getClient(application) }
private val stateListener = object : ClientStateListener {
override fun onReady() {
getReferrer()
}
override fun onError(clientError: ClientError) {
handleReferrerError(clientError)
}
}
fun onResume() {
anyScope.launch(Dispatchers.IO) {
referrerClient.startConnection(stateListener)
}
}
private fun handleReferrerError(referrerError: ClientError) {
when (referrerError) {
ClientError.ERROR_BAZAAR_IS_NOT_INSTALL -> {
// CafeBazaar client is not installed on user device
}
ClientError.ERROR_BAZAAR_IS_NOT_COMPATIBLE -> {
// CafeBazaar client version is not compatible for using the referrer SDK
}
ClientError.ERROR_SDK_COULD_NOT_CONNECT -> {
// Referrer SDK is not able to connect to CafeBazaar client
}
ClientError.ERROR_SDK_IS_STARTED -> {
// startConnection method is called once before and it is ongoing
}
ClientError.ERROR_DURING_GETTING_REFERRER_DETAILS -> {
// An error has occurred during getting the referrer content
}
ClientError.ERROR_DURING_CONSUMING_REFERRER -> {
// An error has occurred during consuming the referrer content
}
}
}