//获得手机版本防止webservice访问网络在4.0以上出现问题
public static String GetSystemVersion(){
return android.os.Build.VERSION.RELEASE;
}
@SuppressLint("NewApi")//兼容低版本
public static void setSystemVersionMethod(Context context) {
String strVer = GetSystemVersion();
strVer=strVer.substring(0,3).trim();
float fv=Float.valueOf(strVer);
if (fv > 2.3) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath().build());
}
}android访问网络兼容高版本,获得版本号
最新推荐文章于 2022-04-02 14:42:07 发布
本文介绍了一种在Android应用中通过检测设备版本来调整网络访问策略的方法,以确保在不同Android版本上都能正常运行。对于4.0以上的版本,通过设置StrictMode策略来检测磁盘读写及网络访问行为,避免潜在的运行时问题。
912

被折叠的 条评论
为什么被折叠?



