Skip to main content
Logo
Explore APIsContact Us
  • Home
  1. Resources
  2. Virtual Stadium
  3. SDK Initialization

SDK Initialization

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.


#Initialize the SDK

The SDK must be initialized once when your application starts. The recommended place to do this is in your custom Application class.

#Step 1: Create or Update Application Class

If you don't already have a custom Application class, create one:

VSDemoApp.kt:

kotlin
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)
    }
}

#Step 2: Register in AndroidManifest.xml

Register your Application class in AndroidManifest.xml:

AndroidManifest.xml:

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>
tip

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.


#Keyboard Configuration

For proper interaction between the chat component and the soft keyboard, you need to configure window insets and input mode settings.

#Window Insets Configuration

Configure whether the window resizes to accommodate the keyboard. This setting depends on how you're using the chat component.

#Full-Screen Chat

If the chat component fills the entire screen, set decorFitsSystemWindows to false:

MainActivity.kt:

kotlin
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()
            )
        }
    }
}

#Partial-Screen Chat

If the chat component is part of a larger layout, set decorFitsSystemWindows to true:

MainActivity.kt:

kotlin
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)
                )
            }
        }
    }
}

#Input Mode Configuration

Set the soft input mode to adjustResize in your AndroidManifest.xml. This ensures the keyboard pushes content up rather than covering it.

AndroidManifest.xml:

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application>
        <activity 
            android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize">
            <!-- ... -->
        </activity>
    </application>

</manifest>
info

The adjustResize mode is crucial for proper keyboard behavior. Without it, the keyboard may cover the input field or cause layout issues.


#Configuration Overview

Here's a complete checklist of the initialization and configuration steps:

StepActionLocationRequired
1Initialize SDKApplication.onCreate()✅ Yes
2Register Application classAndroidManifest.xml✅ Yes
3Configure window insetsActivity.onCreate()✅ Yes
4Set input modeAndroidManifest.xml✅ Yes

#Complete Example

Here's a complete example showing all configuration steps together:

VSDemoApp.kt:

kotlin
import android.app.Application
import ag.sportradar.virtualstadium.uisdk.VirtualStadiumUISDK

class VSDemoApp : Application() {
    override fun onCreate() {
        super.onCreate()
        VirtualStadiumUISDK.init(applicationContext)
    }
}

MainActivity.kt:

kotlin
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:

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>

#Troubleshooting

#SDK Not Initialized Error

If you see an error about the SDK not being initialized:

  • Verify VirtualStadiumUISDK.init() is called in Application.onCreate()
  • Ensure your Application class is registered in AndroidManifest.xml
  • Check that the Application class name includes the correct package

#Keyboard Covering Input

If the keyboard covers the chat input field:

  • Verify windowSoftInputMode="adjustResize" is set in AndroidManifest.xml
  • Check WindowCompat.setDecorFitsSystemWindows() is configured correctly
  • Ensure you're using the correct decorFitsSystemWindows value for your layout

#Layout Issues

If you experience layout problems when the keyboard appears:

  • Try toggling the decorFitsSystemWindows parameter
  • Verify your Compose modifiers are properly configured
  • Check that parent layouts use appropriate size modifiers

#Next Steps

Now 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.

Continue to Chat →
Last updated about 1 month ago
Is this site helpful?
Virtual Stadium, Moderation, Engagement Tools
DependenciesTranslations
On this page
  • Initialize the SDK
  • Step 1: Create or Update Application Class
  • Step 2: Register in AndroidManifest.xml
  • Keyboard Configuration
  • Window Insets Configuration
  • Input Mode Configuration
  • Configuration Overview
  • Complete Example
  • Troubleshooting
  • SDK Not Initialized Error
  • Keyboard Covering Input
  • Layout Issues
  • Next Steps