android4.0后无法向Servlet发送请求解决办法

从4.0开始,强制性地规定网络堵塞任务都不能放在ui线程,不然直接报错。

个办法,在oncreate下面加入

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()       
        .detectDiskReads()       
        .detectDiskWrites()       
        .detectNetwork()   // or .detectAll() for all detectable problems       
        .penaltyLog()       
        .build());       
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()       
        .detectLeakedSqlLiteObjects()    
        .penaltyLog()       
        .penaltyDeath()       
        .build());  
原文地址:https://www.cnblogs.com/xiaoliu66007/p/4570541.html