我从外部蓝牙设备向我的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;
}
}
}