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,哈哈,就是這樣滴!