用的蓝牙模块给手机发消息,用Service进行广播的,但是无论发什么数字接收到的消息都是同一个数字,蓝牙模块是连接在单片机上的
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes; // bytes returned from read()
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer); // bytes数组返回值,为buffer数组的长度
String text = bytesToHexString(buffer);
sendMainMsg(bytes + "");
} catch (Exception e) {
System.out.print("read error");
break;
}
}
接收数据用的是上面的方法,mmInStream是InputStream