RxBluetooth
RxBluetooth copied to clipboard
connect exception
when bluetoothSocket.connect(); log: getBluetoothService() called with no BluetoothManagerCallback java.io.IOException: read failed, socket might closed or timeout, read ret: -1
Discovering process could be an issue as it is a heavyweight procedure.
Make sure you wait until it is over or use BluetoothAdapter.cancelDiscovery()
.
Discovery is not managed by the Activity, but is run as a system service, so an application should always call {@link BluetoothAdapter#cancelDiscovery()} even if it did not directly request a discovery, just to be sure.
Same error as @xiaolingcong
rxBluetooth.observeConnectDevice(device, UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"))
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Consumer<BluetoothSocket>() {
@Override
public void accept(BluetoothSocket socket) throws Exception {
// Connected to the device, do anything with the socket
Log.e("B", "Connected");
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
// Error occured
Log.e("B", "Error: " + throwable.getLocalizedMessage());
}
});
E/B: Error: read failed, socket might closed or timeout, read ret: -1
It is only connecting with my macbook and HC-06 Bluetooth Module but not with any other Bluetooth device like Android.
I think the issue is with UUID because supported UUID list doesn't show UUID that I have coded as Base UUID in code. Any suggestions?
@Muhammad-Soban try to generate your own unique UUID while connecting two Android devices.
If you are connecting to a Bluetooth headset or similar device and if the regular UUIDs don't work , you must first query it for it's supported UUIDs and then use that to connect to it.
I have same error. I'm use SPP + BluetoothProfile.HEADSET.
when call rxBluetooth.connectAsClient(device, UUID_SPP)
=> getBluetoothService() called with no BluetoothManagerCallback
but add .retryWhen { it.delay(500, TimeUnit.MILLISECONDS) }
, always successfully connected after 30 second.