检索Android的API版本编程 [英] Retrieving Android API version programmatically
问题描述
有没有在Android SDK,让我拿到手机正在运行的API版本的任何API?
Is there any API in the Android SDK that allows me to get the API version that the phone is currently running?
推荐答案
由于Android文档中描述,该SDK级别(整数)手机电量可在:
As described in the Android documentation, the SDK level (integer) the phone is running is available in:
<一个href="http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT"><$c$c>android.os.Build.VERSION.SDK_INT$c$c>
对应于这个INT类是在<一个href="http://developer.android.com/reference/android/os/Build.VERSION_$c$cS.html"><$c$c>android.os.Build.VERSION_$c$cS$c$c>类。
The class corresponding to this int is in the android.os.Build.VERSION_CODES
class.
code例如:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
// Do something for lollipop and above versions
} else{
// do something for phones running an SDK before lollipop
}
修改:这SDK_INT可用,因为甜甜圈(Android的1.6 / API4),所以请确保您的应用程序不符合蛋糕(Android的1.5 / API3)当您使用它,或者你的应用程序将复古兼容崩溃(感谢程序员布鲁斯为precision)。
Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).
Corresponding android documentation is here and here
这篇关于检索Android的API版本编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!