天天看點

android 添加網絡權限後還是不能通路網絡

在4.2以上的系統再添加通路權限之後,發現仍然不能通路網絡。

需要添加以下代碼:

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
		.detectDiskReads()
		.detectDiskWrites()
		.detectNetwork()
		.penaltyLog()
		.build());      
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()      
		.detectLeakedSqlLiteObjects()      
		//.detectLeakedClosableObjects()      
		.penaltyLog()      
		.penaltyDeath()      
		.build());
           

在setcontentView();方法之後