检查并中断do-while循环

时间:2014-09-16 03:45:09

标签: java android bluetooth

我从外部蓝牙设备向我的Android设备发送串行数据,如下所示:

发送'*'---->发送数据---->发送'#'

有人可以告诉我为什么这段代码不起作用?它没有显示任何内容。

在接收端,代码如下: BluetoothChat.java

public String myteststring;
private static boolean check=true;

// The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        switch (msg.what) {

            case MESSAGE_READ:

                byte[] readBuf = (byte[]) msg.obj;

                // construct a string from the valid bytes in the buffer
                String readMessage = new String(readBuf, 0, msg.arg1);

                if(!readMessage.matches("\\*")) {
                    mConversationArrayAdapter.add("Error!");
                    check=false;
                }

                do {
                    if(readMessage.matches("\\*")) {
                        mConversationArrayAdapter.add("Start");
                        myteststring = " ";

                    } else if(readMessage.matches("\\#")) {
                        mConversationArrayAdapter.add(myteststring);
                        mConversationArrayAdapter.add("End");
                        break;
                    } else  {
                        //mConversationArrayAdapter.add(readMessage);
                        myteststring=myteststring.concat(readMessage);
                    }

                } while(check);

             case MESSAGE_WRITE:
                    //code
                    break;
        }
    }
}

0 个答案:

没有答案