【发布时间】:2018-11-13 02:08:20
【问题描述】:
我想使用RxBluetooth 在两台 Android 设备之间传输一些文本。 我可以扫描并查看附近的设备,但在尝试连接其中一个设备时遇到以下故障:
D/BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null
W/BluetoothAdapter: getBluetoothService() 在没有 BluetoothManagerCallback 的情况下调用
D/BluetoothSocket: connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[65]}
java.io.IOException: 读取失败,socket 可能关闭或超时,读取 ret: -1
这是我为了与选定的BluetoothDevice 建立连接而运行的代码:
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
}
})
两台设备都启用了蓝牙,因为我可以从另一台设备中发现一台。
我使用的权限是:
<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"/>
谢谢。
【问题讨论】:
-
FWIW, this sample app 使用 RxBluetooth 在两个设备之间传输文本。
标签: android bluetooth rx-java2 rxbluetooth