Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Q emulator - Build.VERSION.SDK_INT returns 28

 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'
like image 212
user1159819 Avatar asked Apr 06 '19 02:04

user1159819


People also ask

What is build version Sdk_int?

VERSION. To fetch information about the version that your device is running on, you need to access Build. VERSION class: SDK_INT: The SDK version of the software currently running on this hardware device.

What is the SDK version of Android 11?

Android 11 (API level 30)

How do I know if Android SDK is installed?

All of the packages are downloaded into your Android SDK directory, which you can locate as follows: In Android Studio, click File > Project Structure. Select SDK Location in the left pane. The path is shown under Android SDK location.

What is Android Target SDK version?

android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level.


2 Answers

Before the API is finalized and officially becomes API 29 (where you'd use compileSdkVersion 29, etc), you must use BuildCompat.isAtLeastQ():

Checks if the device is running on a pre-release version of Android Q or newer.

Note: This method will return false on devices running release versions of Android. When Android Q is finalized for release, this method will be deprecated and all calls should be replaced with Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q.

like image 75
ianhanniballake Avatar answered Sep 27 '22 18:09

ianhanniballake


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 there

  • Create res/values-v29/bools.xml and put <bool name="isQ">true</bool> in there

At this point, if you refer to the isQ resource, you will get true on Android Q and higher devices, false otherwise.

like image 42
CommonsWare Avatar answered Sep 27 '22 18:09

CommonsWare