检索Android的API版本编程
有没有在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:
android.os.Build.VERSION.SDK_INT$c$c>
对应于这个INT类是在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