以编程方式 Android API 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3506792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:31:40  来源:igfitidea点击:

Android API Version programmatically

android

提问by rbz

Possible Duplicate:
Retrieving Android API version programmatically

可能的重复:以
编程方式检索 Android API 版本

I am trying to retrieve the current API Version of the device my Application is Running. Is there a way i can get that and Store it on a String. This needs to Work on 1.5 Version and Up. Examples would be greatly appreciated. Thank you.

我正在尝试检索我的应用程序正在运行的设备的当前 API 版本。有没有办法我可以得到它并将它存储在一个字符串上。这需要在 1.5 版本及更高版本上工作。示例将不胜感激。谢谢你。

回答by iandisme

You can get it by calling Build.VERSION.SDK.

您可以通过调用获取它Build.VERSION.SDK

From 1.6 on, you should use Build.VERSION.SDK_INTinstead
because Build.VERSION.SDKis deprecated.

从 1.6 开始,您应该Build.VERSION.SDK_INT改用,
因为Build.VERSION.SDK已弃用。

回答by Falcon165o

Build.VERSION.RELEASE;

That will give you the actual numbers of your version; aka 2.3.3 or 2.2.

这将为您提供版本的实际数字;又名 2.3.3 或 2.2。

The problem with using Build.VERSION.SDK_INT is if you have a rooted phone or custom rom, you could have a none standard OS (aka my android is running 2.3.5) and that will return a NULLwhen using Build.VERSION.SDK_INT so Build.VERSION.RELEASE will work no matter what!

使用 Build.VERSION.SDK_INT 的问题是,如果你有一个根电话或自定义 rom,你可能有一个非标准的操作系统(也就是我的 android 运行的是 2.3.5)并且NULL在使用 Build.VERSION.SDK_INT 时会返回一个Build.VERSION.RELEASE 无论如何都可以使用!

回答by Konstantin Burov

It is defined on the android.os.Build.VERSION.SDKconstant, just use it.

它是在android.os.Build.VERSION.SDK常量上定义的,只需使用它。