我改用DataInputStreams,因为您可以执行readFully()方法,该方法在返回之前等待读取一定数量的字节。我这样设置BT连接:
BluetoothDevice btDevice = bta.getRemoteDevice(macAddress);BluetoothSocket btSocket = InsecureBluetooth.createRfcommSocketToServiceRecord( btDevice, UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), false);btSocket.connect();InputStream input = btSocket.getInputStream();DataInputStream dinput = new DataInputStream(input);
然后稍后当我想阅读时,我使用readFully:
dinput.readFully(byteArray, 0, byteArray.length);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)