android最麻烦的是版本问题,高版本兼容低版本,而低版本却很大一部分用不了高版本,所以为了实现兼容,需要对手机版本或者系统进行检测:
public String[] getVersion(){
String[] version={"null","null","null","null"};
String str1 = "/proc/version";
String str2;
String[] arrayOfString;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(
localFileReader, 8192);
str2 = localBufferedReader.readLine();
arrayOfString = str2.split("\\s+");
version[0]=arrayOfString[2];//KernelVersion
localBufferedReader.close();
} catch (IOException e) {
}
version[1] = Build.VERSION.RELEASE;// firmware version
version[2]=Build.MODEL;//model
version[3]=Build.DISPLAY;//system version
return version;
}
上面的也许可以解决一部分问题了,不过还是有点麻烦,当然有更简单的了:
public static int getSDKVersionNumber() {
int sdkVersion;
try {
sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK);
} catch (NumberFormatException e) {
sdkVersion = 0;
}
return sdkVersion;
}
这个就是,像2.2版本是8,2.3.3版本是10,哈哈,就是这样滴!