Android version check

主宰稳场 提交于 2019-11-30 04:11:06

Well, you must compile your project with the latest SDK version. Your constants are replaced with corresponding integer values during compilation. No matter what version of Android you run the application on - integers are the same

Well in that case use this

// Check if we're running on Android 5.0 or higher
if (Build.VERSION.SDK_INT >= 21) {
    // Call some material design APIs here
} else {
    // Implement this feature without material design
}

Build.VERSION_CODES.LOLLIPOP = 21

Try this one

 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
       // Marshmallow+
   }else{
        //below Marshmallow
}

Note: Build.VERSION_CODES.LOLLIPOP_MR1==22

    Build.VERSION_CODES.M==23

Bit a late to answer, but, today I encountered with the same issue on Android Studio 3.4.1

So the workaround is:

Upgrade to the latest Android SDK.

And,

After Marshmallow/Android 6 Build.VERSION_CODES.xxx full names are replaced with initials and some other variations.

So, now for Marshmallow, it will be: Build.VERSION_CODES.M

And for Nougat: Build.VERSION_CODES.N

And so on.

Read more about the build version codes here: Android Developer Reference

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