解决方案 »

  1.   

    public void run(){
    byte[] buff = new byte[1024];
    int bytes = -1;
    while(true){
    try {
    bytes = inputStream.read(buff);
    if(bytes != -1){
    byte[] buf_data = new byte[bytes];
    for(int i=0; i<bytes; i++){
    buf_data[i] = buff[i];
    }
    msg = new String(buf_data);
    testResultDetails.message = msg;
    }
    else{
    String msg = "no data receive restart you phone";
    Log.i("data",  msg);
    testResultDetails.message = msg;
    }
    } catch (IOException e) {
    Log.e("app", "失去连接");
    e.printStackTrace();
    }
    }
    }
      

  2.   

    public void run(){
    byte[] buff = new byte[1024];
    int bytes = -1;
    while(true){
    try {
    Log.i("State", "开始接受数据ClientReceiveData");
    bytes = inputStream.read(buff);
    if(bytes != -1){
    Log.i("bytes", bytes+"BBBBBBBBBBBBB");
    byte[] buf_data = new byte[bytes];
    for(int i=0; i<bytes; i++){
    buf_data[i] = buff[i];
    }
    msg += new String(buf_data);
    msg = msg.trim();
    flag ++;
    Log.i("data",  "MMMMMMMMM"+msg);
    if(("[").equals((String)msg.subSequence(0,1)) && ("]").equals(msg.substring(msg.length()-1))){
    Log.i("data",  msg);
    testResultDetails.message = msg;
    msg = "";
    flag = 0;
    }
    if(flag == 2){
    msg = "";
    flag = 0;
    }
    }
    else{
    Log.i("bytes", "CCCCCCCCCCC");
    String msg = "no data receive restart you phone";
    Log.i("data",  msg);
    testResultDetails.message = msg;
    }
    } catch (IOException e) {
    // TODO 自动生成的 catch 块
    Log.e("app", "失去连接");
    e.printStackTrace();
    }



    }
    }