Integrate our SDK into your app
Application class
Pass the application context to the `AssistSession` in the `onCreate` of the base application.
class TestApplication: AssistSDKApplication() {
override fun onCreate() {
super.onCreate()
AssistSession.INSTANCE.setContext(this)
}
}
MainActivity class
Start the `AssistSession` in the activity and set up all the necessary lifecycle methods as shown below.
class MainActivity : AppCompatActivity() {
private lateinit var callback: ISessionCallbacks
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
callback = ISessionCallbacks(this, viewDataBinding)
AssistSession.INSTANCE.onCreate(this, TestCallbacks())
AssistSession.INSTANCE
.setCallbacks(callback) //pass over an instance of class implementing SessionCallbacks.
.setCustomerDetails(
"name",
"email@emailcom"
) // share username and userEmail - Default value is Guest
.setAuthToken(authToken)
.setPluginToast(true)
.enableFloatingHead(true)
.shareScreenOnStart(true)
.downloadAddonOnStart(true)
.setQuality(Constants.ColorQualityFactors.QUALITY75)
.setKeepAliveNotification(getNotification())
.start(
key,
MainActivity::class.java,
R.drawable.assist_flat
)
AssistSession.serviceQueueResponseCallback = this
if(AssistSession.INSTANCE.isEnrolled(this)){
AssistSession.INSTANCE.checkAndStartSession()
/**
* After call the above function, add delay for 2 seconds and update your UI based on service queue result.
*/
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
data?.let {
AssistSession.INSTANCE.onActivityResult(requestCode, resultCode, it)
}
}
override fun onStop() {
super.onStop()
AssistSession.INSTANCE.onStop()
}
override fun onResume() {
super.onResume()
AssistSession.INSTANCE.onResume()
}
override fun onBackPressed() {
//Handle what happens when the back button is pressed
if (!AssistSession.INSTANCE.isSessionAlive()) {
super.onBackPressed()
} else {
AssistSession.INSTANCE.onCustomerEndSession()
}
}
override fun sessionEnded(reason: String) {
// This callback is for Service Queue
// Handle your UI based on the result
}
override fun sessionInitiated(sessionKey: String) {
// This callback is for Service Queue
//Initiate the session using this session key.
//Handle your UI based on the result
}
}