我有安卓应用。我使用 BLE(蓝牙低功耗)连接到设备。效果很好,但我在 Android 10 上有问题。这是我的代码:
Hashtable<String, BluetoothDevice> myHtDevices;
....
BluetoothGatt gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback);
Run Code Online (Sandbox Code Playgroud)
在 onConnectionStateChange 我得到:
//public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState){
status= 133,
newStatus =0,
Run Code Online (Sandbox Code Playgroud)
我只有 Android Q 有这个问题。
我试过这个方法(添加参数TRANSPORT_LE),但它不起作用:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q){
gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback,
BluetoothDevice.TRANSPORT_LE);
}
else {
gatt = myHtDevices.get(deviceId).connectGatt(this, false, gattCallback);
}
Run Code Online (Sandbox Code Playgroud)
添加信息:
我通过执行 BLE 扫描获得 myHtDevices。
我马上回电过来。
设备-三星9
这是 nRF 连接日志:
nRF Connect, 2020-03-24
Device (50:8C:B1:52:B7:8D)
V 19:37:26.248 Connecting to 50:8C:B1:52:B7:8D...
D 19:37:26.248 gatt = device.connectGatt(autoConnect = …
Run Code Online (Sandbox Code Playgroud)