Is it possible to detect if an user is running Android N?
I have a Nexus 6 with the Android N Developer Preview. If I try to get the build version with Build.VERSION.SDK_INT
, it returns 23 which is equal to Android Marshmallow.
Is it possible to detect if an user is running Android N?
I have a Nexus 6 with the Android N Developer Preview. If I try to get the build version with Build.VERSION.SDK_INT
, it returns 23 which is equal to Android Marshmallow.
I would recommend using Integer value for checking Android version rather than String
Just remember it's necessary to have compileSdkVersion to 24 or higher in manifests.xml:
Approach 1: (recommended) Use support library
android.support.v4.os.BuildCompat.isAtLeastN
.Approach 2: Use this as the "real" version code:
Build.VERSION.SDK_INT < 23 || Build.VERSION.PREVIEW_SDK_INT == 0 ? Build.VERSION.SDK_INT : Build.VERSION.SDK_INT + 1
.I found that the behaviour of Build.VERSION.RELEASE and Build.VERSION.CODENAME is quite different depending on whether it's a full production release of Android OS or a developer preview. We went with the following mechanism. You can't rely on just one value if you want to account for more than one scenario.
This is what I found was the case for a Galaxy S7 running a production release of Nougat and a Nexus 5X running O DP1.
Galaxy S7 Nougat Build.VERSION.BASE_OS: Build.VERSION.CODENAME: REL Build.VERSION.INCREMENTAL: G930FXXU1DQB3 Build.VERSION.PREVIEW_SDK_INT: 0 Build.VERSION.RELEASE: 7.0 Build.VERSION.SDK_INT: 24 Build.VERSION.SECURITY_PATCH: 2017-01-01
Nexus 5X O Build.VERSION.BASE_OS: Build.VERSION.CODENAME: O Build.VERSION.INCREMENTAL: 3793265 Build.VERSION.PREVIEW_SDK_INT: 1 Build.VERSION.RELEASE: O Build.VERSION.SDK_INT: 25 Build.VERSION.SECURITY_PATCH: 2017-03-05
Quoting myself:
I haven't looked at
Build.VERSION.RELEASE
, as suggested by zgc7009's comment, though that too may be a possibility.Also, if you are reading this from the far future, where Android N has shipped in final form, you should be able to use
Build.VERSION.SDK_INT
andBuild.VERSION_CODES.N
. The above hack is due to the idiosyncrasies of how Google handles these developer previews.