以编程方式检查 Android 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26035310/
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
Checking Android version programmatically
提问by ssh
I need to check the Android version of my phone and if the version is less than 4.0.0 i should execute the following code otherwise it should not execute. How could I do it? I used this line to get the Android version.
我需要检查我手机的 Android 版本,如果版本低于 4.0.0,我应该执行以下代码,否则它不应该执行。我怎么能做到?我用这一行来获取 Android 版本。
String androidOS = Build.VERSION.RELEASE;
How could I check whether less than 4.0.0. Suggest me a solution.
我如何检查是否小于 4.0.0.0.0。建议我一个解决方案。
回答by Kushal Sharma
回答by Bhanu Sharma
You can get any detail about phone like this -> and android.os.Build help you to get this
您可以像这样获得有关手机的任何详细信息 -> 和 android.os.Build 可以帮助您获得此信息
System.out.println("button press on device name = "+android.os.Build.MODEL +" brand = "+android.os.Build.BRAND +" OS version = "+android.os.Build.VERSION.RELEASE + " SDK version = " +android.os.Build.VERSION.SDK_INT);
回答by Supriya
use
用
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 14) {
// Do something for 14 and above versions
} else {
// do something for phones running an SDK before 14
}
回答by Pratik Dasa
Try below code:
试试下面的代码:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD){
// Do your code for froyo and above versions
} else{
// do your code for before froyo versions
}