android.os.NetworkOnMainThreadException 异常处理

android4.0时候提示 android.os.NetworkOnMainThreadException异常,在2.3以下无

在appliction里添加 

int fv =android.os.Build.VERSION.SDK_INT;
		
		if (fv>10) { 
			StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()  
	        .detectDiskReads()  
	        .detectDiskWrites()  
	        .detectNetwork()   // or .detectAll() for all detectable problems  
	        .penaltyLog()  
	        .build());  
			StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()  
	        .detectLeakedSqlLiteObjects()  
	        .detectLeakedClosableObjects()  
	        .penaltyLog()  
	        .penaltyDeath()  
	        .build());  
		}

 

你可能感兴趣的:(android.os.NetworkOnMainThreadException 异常处理)