Reputation: 328
I am trying to check the android 12 API level using the below code.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
// Do something for Android 12 and above versions
}
else
{
// Do something for phones running an SDK before Android 12
}
but always execute else part when the run application in the android 12 beta device. is it another way to check the android 12 beta version?
Upvotes: 4
Views: 9781
Reputation: 436
BuildCompat.isAtLeastXX(), XX is your target version.
if (BuildCompat.isAtLeastS()) {
//Checks if the device is running on a pre-release version of Android S or a release version of Android S or newer.
}
https://developer.android.com/reference/androidx/core/os/BuildCompat#isAtLeastS()
Upvotes: 2
Reputation: 1248
To also detect Android 12 Beta versions you can use Build.VERSION.CODENAME
like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || "S".equals(Build.VERSION.CODENAME)) {
// Android 12 or Android 12 Beta
}
Upvotes: 7