Android RxBluetooth无法与设备建立连接

Android RxBluetooth无法与设备建立连接,android,bluetooth,rx-java2,rxbluetooth,Android,Bluetooth,Rx Java2,Rxbluetooth,我想用它在两台Android设备之间传输一些文本。 我能够扫描并查看附近的设备,但在尝试连接到其中一个设备时,我会遇到以下故障: D/BluetoothUtils:IsSocketAllowedBySecurity策略启动:设备空 W/BluetoothAdapter:getBluetoothService()在没有BluetoothManagerCallback的情况下调用 D/BluetoothSocket:connect(),SocketState:INIT,mPfd:{ParcelFi

我想用它在两台Android设备之间传输一些文本。 我能够扫描并查看附近的设备,但在尝试连接到其中一个设备时,我会遇到以下故障:


D/BluetoothUtils:IsSocketAllowedBySecurity策略启动:设备空

W/BluetoothAdapter:getBluetoothService()在没有BluetoothManagerCallback的情况下调用

D/BluetoothSocket:connect(),SocketState:INIT,mPfd:{ParcelFileDescriptor:FileDescriptor[65]}

java.io.IOException:读取失败,套接字可能关闭或超时,读取ret:-1


这是我运行的代码,用于与所选的
蓝牙设备建立连接

mRxBluetooth.observeConnectDevice(bluetoothDevice, UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
            .subscribeOn(mSchedulerProvider.io())
            .observeOn(mSchedulerProvider.ui())
            .subscribe(new Consumer<BluetoothSocket>() {
                @Override
                public void accept(BluetoothSocket bluetoothSocket) throws Exception {
                    // Unable to reach here.
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    // I reach this point with the message:
                    // java.io.IOException: read failed, socket might closed or timeout, read ret: -1
                }
            })
mRxBluetooth.observeConnectDevice(蓝牙设备,UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”))
.subscribeOn(mSchedulerProvider.io())
.observeOn(mSchedulerProvider.ui())
.订阅(新消费者){
@凌驾
公共void接受(BluetoothSocket BluetoothSocket)引发异常{
//我到不了这里。
}
},新消费者(){
@凌驾
public void accept(Throwable Throwable)引发异常{
//我要说的是:
//java.io.IOException:读取失败,套接字可能已关闭或超时,读取ret:-1
}
})
蓝牙在两个设备上都启用,因为我能够从一个设备发现另一个设备

我使用的权限是:

<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="true"/>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

谢谢。

问题解决了。 我忘了
observeBluetoothSocket()

的(Commonware评论中建议的示例应用程序)帮助我认识到了这一事实。 还帮助我发现了从套接字读取数据非常方便的原因:

        Strings.from(btSocket.getInputStream())
           .subscribeOn(mSchedulerProvider.io())
           .observeOn(mSchedulerProvider.ui())
           .subscribe(data -> {/* Post data to LiveData*/},
                   throwable -> {/* Handle error*/});
感谢您抽出时间阅读我的问题。

FWIW,使用RxBluetooth在两台设备之间传输文本。
        Strings.from(btSocket.getInputStream())
           .subscribeOn(mSchedulerProvider.io())
           .observeOn(mSchedulerProvider.ui())
           .subscribe(data -> {/* Post data to LiveData*/},
                   throwable -> {/* Handle error*/});