Android Q emulator - Build.VERSION.SDK_INT returns 28

梦想与她 提交于 2019-12-02 02:27:41

问题


 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'

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/55545250/android-q-emulator-build-version-sdk-int-returns-28

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!