Я пытаюсь подключиться к HC-06 через Bluetooth с устройства Android. Мне удалось заставить его работать до использования:Ошибка подключения Bluetooth к Bluetooth
bluetoothSocket = (BluetoothSocket) bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(this.bluetoothDevice,1);
проблема в том, что он работает только один раз. когда я отключаю и закрыть входные и выходные потоки, а затем сокет, а затем попытаться восстановить это дает мне эту ошибку:
D/BluetoothSocket: connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[55]}
D/BluetoothSocket: close() in, this: [email protected], channel: 1, state: INIT
D/BluetoothSocket: close() this: [email protected], channel: 1, mSocketIS: [email protected], mSocketOS: [email protected]: [email protected] impl:[email protected] fd:FileDescriptor[55]
D/BluetoothSocket: Closing mSocket: [email protected] impl:[email protected] fd:FileDescriptor[55]
W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
W/System.err: at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:739)
W/System.err: at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:716)
W/System.err: at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:482)
W/System.err: at com.example.work.dmm.clientBluetoothConnection.run(clientBluetoothConnection.java:65)
Я пытался искать проблемы и найти различные сообщения, говоря, что createRfcommSocketToServiceRecord() должен вместо этого. Я пробовал:
ParcelUuid[] uuids = bluetoothDevice.getUuids();
UUID uuid = uuids[0].getUuid();
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid);
но это совсем не работает. Я не уверен, куда идти отсюда, поэтому любая помощь ценится.