我正在努力解决蓝牙问题。我写了一个从ELM 327蓝牙接口接收数据的应用程序,当我使用蓝牙终端应用程序时,我收到了#34; clean"像
这样的数据127 00 00 00 00 00 00 0D
我不知道如何摆脱这个问号,这到底是什么?该消息还包含类似
的内容{When = 0 what = 0 obj = n}
另外如何摆脱这个?
贝娄是我的代码,我将非常非常感谢你的帮助..
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Intent sendIntent = new Intent();
if (msg.what == handlerState) {
recDataString.append(msg);
Log.d("tablica", String.valueOf(recDataString));
int startOf = recDataString.indexOf("176");
int endOf = recDataString.indexOf("<");
if (recDataString.length() > 23) {
String stringMessage = String.valueOf(recDataString);
if (stringMessage.contains(" ")) {
stringMessage = stringMessage.replace(" ", "");
//Log.d("spacje", stringMessage);
int lengthOfString = stringMessage.length();
if(stringMessage.contains("176")) {
stringMessage = stringMessage.substring(startOf-3, startOf+17);
Log.d("spacje", stringMessage);
}
}
}
recDataString.delete(0, recDataString.length());
}
}
}
这是运行方法
@Override
public void run() {
super.run();
byte[] mmBuffer = new byte[1024];
int mmBytes = 0;
int begin = 0;
while (true) {
try {
mmBytes += mmInStream.read(mmBuffer, mmBytes, mmBuffer.length - mmBytes);
for (int i = begin; i < mmBytes; i++) {
if ( mmBytes > 13 ) {
mmBuffer[i] += ">".getBytes()[0];
String wiadomosc = new String(mmBuffer);
Message msg = new Message();
msg.obj = wiadomosc;
h.sendMessage(msg);
if (i == mmBytes - 1) {
mmBytes = 0;
begin = 0;
}
mmBytes = 0;
}
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Input stream was disconnected", Toast.LENGTH_LONG).show();
break;
}
}
}
我几天都在努力解决这个问题,我不知道如何解决这个问题。此方法也在服务中。求你帮忙