---
title: "android网络访问兼容"
author: "august_000"
date: "2012-08-19T11:04:47Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2012-08-19T11:04:47Z"
id: 1637027
url: "https://sharemu.iteye.com/blog/1637027"
---

```java
	public static void version4Adapter() {
		String strVer = android.os.Build.VERSION.RELEASE;
		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().detectLeakedClosableObjects()
					.penaltyLog().penaltyDeath().build());

		}

	}
```



```java

 public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       OSInfoUtil.version4Adapter();
//TODO:
}

```