有什么办法可以获取手机当前运行的API版本吗?
Is there any way 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
这个int对应的类在android.os.Build.VERSION_CODES 类.
The class corresponding to this int is in the android.os.Build.VERSION_CODES class.
代码示例:
if (android.os.Build.VERSION.SDK_INT >= 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 自 Donut (android 1.6/API4) 起可用,因此请确保您的应用程序在使用时不与 Cupcake (android 1.5/API3) 兼容,否则您的应用程序将崩溃(感谢程序员布鲁斯的精确性).
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).
对应的安卓文档是这里和这里
更多推荐
以编程方式检索 Android API 版本
发布评论