import android.os.Build
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class SdkInfoActivity : AppCompatActivity() {
private lateinit var sdkVersionTextView: TextView
private lateinit var apiLevelTextView: TextView
private lateinit var refreshButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sdk_info)
sdkVersionTextView = findViewById(R.id.sdkVersionTextView)
apiLevelTextView = findViewById(R.id.apiLevelTextView)
refreshButton = findViewById(R.id.refreshButton)
fun updateSdkInfo() {
val sdkVersion = Build.VERSION.RELEASE ?: "Unknown"
val apiLevel = Build.VERSION.SDK_INT.toString()
sdkVersionTextView.text = "SDK Version: $sdkVersion"
apiLevelTextView.text = "API Level: $apiLevel"
}
updateSdkInfo()
refreshButton.setOnClickListener {
updateSdkInfo()
}
}
}This code uses Build.VERSION.RELEASE to get the Android SDK version as a string, like "13" or "12". It uses Build.VERSION.SDK_INT to get the API level as an integer, like 33 or 31.
We define a function updateSdkInfo() that sets the text of the two TextViews with this info. We call it once when the screen loads to show the info immediately.
The Refresh button has a click listener that calls updateSdkInfo() again, so if the device info changes (rare but possible), the user can update the display.
This keeps the UI simple and clear, with accessible text labels and a button that updates the info on demand.