Before using any Virtual Stadium UI components, you must initialize the SDK in your Android application. This guide covers the initialization process and essential configuration steps.
The SDK must be initialized once when your application starts. The recommended place to do this is in your custom Application class.
If you don't already have a custom Application class, create one:
VSDemoApp.kt:
import android.app.Application
import ag.sportradar.virtualstadium.uisdk.VirtualStadiumUISDK
class VSDemoApp : Application() {
override fun onCreate() {
super.onCreate()
// Initialize Virtual Stadium UI SDK
VirtualStadiumUISDK.init(applicationContext)
}
}Register your Application class in AndroidManifest.xml:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<application
android:name=".VSDemoApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.App">
<!-- Your activities -->
<activity android:name=".MainActivity">
<!-- ... -->
</activity>
</application>
</manifest>The init() method should be called only once, in the onCreate() of your Application class. Calling it multiple times or in other locations may cause unexpected behavior.
For proper interaction between the chat component and the soft keyboard, you need to configure window insets and input mode settings.
Configure whether the window resizes to accommodate the keyboard. This setting depends on how you're using the chat component.
If the chat component fills the entire screen, set decorFitsSystemWindows to false:
MainActivity.kt:
import androidx.core.view.WindowCompat
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Chat fills the screen
WindowCompat.setDecorFitsSystemWindows(
window,
decorFitsSystemWindows = false
)
setContent {
Chat(
jwtToken = "<jwt-token>",
channelId = "<channel-id>",
modifier = Modifier.fillMaxSize()
)
}
}
}If the chat component is part of a larger layout, set decorFitsSystemWindows to true:
MainActivity.kt:
import androidx.core.view.WindowCompat
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Chat is part of the layout
WindowCompat.setDecorFitsSystemWindows(
window,
decorFitsSystemWindows = true
)
setContent {
Column {
TopAppBar(/* ... */)
Chat(
jwtToken = "<jwt-token>",
channelId = "<channel-id>",
modifier = Modifier.weight(1f)
)
}
}
}
}Set the soft input mode to adjustResize in your AndroidManifest.xml. This ensures the keyboard pushes content up rather than covering it.
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<!-- ... -->
</activity>
</application>
</manifest>The adjustResize mode is crucial for proper keyboard behavior. Without it, the keyboard may cover the input field or cause layout issues.
Here's a complete checklist of the initialization and configuration steps:
| Step | Action | Location | Required |
|---|---|---|---|
| 1 | Initialize SDK | Application.onCreate() | ✅ Yes |
| 2 | Register Application class | AndroidManifest.xml | ✅ Yes |
| 3 | Configure window insets | Activity.onCreate() | ✅ Yes |
| 4 | Set input mode | AndroidManifest.xml | ✅ Yes |
Here's a complete example showing all configuration steps together:
VSDemoApp.kt:
import android.app.Application
import ag.sportradar.virtualstadium.uisdk.VirtualStadiumUISDK
class VSDemoApp : Application() {
override fun onCreate() {
super.onCreate()
VirtualStadiumUISDK.init(applicationContext)
}
}MainActivity.kt:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import ag.sportradar.virtualstadium.uisdk.compose.Chat
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Configure window for keyboard interaction
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
Chat(
jwtToken = "<your-jwt-token>",
channelId = "<your-channel-id>",
languageCode = LanguageCode.EN,
modifier = Modifier.fillMaxSize()
)
}
}
}AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vsdemo">
<application
android:name=".VSDemoApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.App">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>If you see an error about the SDK not being initialized:
VirtualStadiumUISDK.init() is called in Application.onCreate()AndroidManifest.xmlIf the keyboard covers the chat input field:
windowSoftInputMode="adjustResize" is set in AndroidManifest.xmlWindowCompat.setDecorFitsSystemWindows() is configured correctlydecorFitsSystemWindows value for your layoutIf you experience layout problems when the keyboard appears:
decorFitsSystemWindows parameterNow that the SDK is initialized and configured, you're ready to implement the chat component:
Implement Chat Component
Learn how to add the Chat component to your app with all its parameters, features, and customization options.