Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Android 12 API level?

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?

like image 711
B'havdip Dhameliya Avatar asked Oct 28 '25 14:10

B'havdip Dhameliya


2 Answers

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
}
like image 111
Oliver Jonas Avatar answered Oct 31 '25 10:10

Oliver Jonas


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

like image 26
laomo Avatar answered Oct 31 '25 10:10

laomo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!