在android程序中加这两句话:降低版本,android 3.0以上版本需要加
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath().build());
位置:Oncreat方法下面即可
例如:
public class TIDSDemoActivity extends Activity {//
private EditText mEditText_show = null;
private Button mBotton_serversocket = null;
private Button mButton_socket = null;
private Socket mSocket = null;
private ServerSocket mServerSocket = null;
private String mString ="";
private BufferedReader mBufferedReader = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
//降低版本
/* StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath().build());*/
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);