運行時獲取Android API版本

As described in the android documentation, the SDK level (integer) the phone is running is available in:html

android.os.Build.VERSION.SDK_INT;android

The enum corresponding to this int is in the android.os.Build.VERSION_CODES class.api

Code example:app

int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){     // Do something for froyo and above versions } else{     // do something for phones running an SDK before froyo } 

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).post

Corresponding android documentation:ui

http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INTthis

http://developer.android.com/reference/android/os/Build.VERSION_CODES.htmlspa

相關文章
相關標籤/搜索