Android版本检查 [英] Android version check

查看:110
本文介绍了Android版本检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Android并不陌生,并且已经习惯了版本处理以及如何进行条件处理,但是当我看到困扰我...

I'm not new to Android and I'm well used to the version handling and how to condition it, but when I see this it troubles me...

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

在棒棒糖之前的任何设备上,此行都会使应用程序崩溃,因为 Build.VERSION_CODES.LOLLIPOP 字段不存在...为什么在文档的推荐解决方案中使用此功能?

On any device pre lollipop this line would crash the app because the Build.VERSION_CODES.LOLLIPOP field does not exists... so why is this in the recommended solution in the documentation?

我真的想知道我想念什么吗?

I'm really wondering what am I missing?

推荐答案

好吧,您必须使用最新的SDK版本编译您的项目。在编译过程中,常量将替换为相应的整数值。无论您在哪个版本的Android上运行应用程序-整数都是相同的

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

这篇关于Android版本检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆