解决android SDK2.3.3以后访问网络虚拟机可以真机报错问题

 在activity中onCreate方法加入

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
				.detectDiskReads().detectDiskWrites().detectNetwork()
				.penaltyLog().build());
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
				.detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath()
				.build());// 打印logcat//探测SQLite


列子:

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
				.detectDiskReads().detectDiskWrites().detectNetwork()
				.penaltyLog().build());
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
				.detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath()
				.build());// 打印logcat//探测SQLite

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();

	}

AndroidManifest.xml中加入网络访问权限

<uses-permission android:name="android.permission.INTERNET" />



你可能感兴趣的:(解决android SDK2.3.3以后访问网络虚拟机可以真机报错问题)