Build.VERSION.SDK_INT
returns 28 instead of 29 when running on Android Q emulator. Is there anything I am missing? I am trying to add logic specifically for Android Q but I do not know how to determine this version correctly.
app.gradle file contains
targetSdkVersion = 'Q'
compileSdkVersion = 'android-Q'
Before the API is finalized and officially becomes API 29 (where you'd use
compileSdkVersion 29
, etc), you must useBuildCompat.isAtLeastQ()
:Note that Ian's solution requires AndroidX and is only available from Java/Kotlin code.
If your project is not ready for AndroidX just yet, or you need the value in a resource or the manifest, you can use
bool
resources:Create
res/values/bools.xml
and put<bool name="isQ">false</bool>
in thereCreate
res/values-v29/bools.xml
and put<bool name="isQ">true</bool>
in thereAt this point, if you refer to the
isQ
resource, you will gettrue
on Android Q and higher devices,false
otherwise.