连接设备时出现Android BLE GATT_ERROR(133)错误

13

我正在尝试使用MAC地址连接到一个BLE设备。

BluetoothDevice device = bluetoothAdapter.getRemoteDevice(rememberedDeviceAddress)
bluetoothDevice.connectGatt(context, false, bluetoothGattCallback);

即使我的BLE设备已经关闭,我在BluetoothGattCallback.onConnectionStateChange中收到一个回调,其中status = 133newState = 2newState = 2是指连接状态为BluetoothProfile.STATE_CONNECTED,而status = 133是GATT_ERROR(而不是status = 0 SUCCESS)。

我没有收到“无法注册回调”的错误。

设备:One plus one(Android 4.4)

对于可能导致此问题的原因的任何指针都将有所帮助。

注意:并非所有设备都会出现此问题。 在Android 5.0上使用Nexus 5时似乎一切正常。

请查看以下堆栈跟踪:

03-06 13:00:11.994: D/BluetoothGatt(26771): registerApp()
03-06 13:00:11.994: D/BluetoothGatt(26771): registerApp() - UUID='uuid comes here'
03-06 13:00:12.004: D/BluetoothGatt(26771): onClientRegistered() - status=0 clientIf=5
03-06 13:00:42.004: D/BluetoothGatt(26771): onClientConnectionState() - status=133 clientIf=5 device='device id comes here'

1
请查看此问题的建议答案:https://dev59.com/HoXca4cB1Zd3GeqPMr3E - PaulT
你能解决这个问题吗?我也遇到了同样的问题。 - Borzh
1个回答

2
某些设备需要在UI线程上运行Bluetooth LE交互。因此,我建议尝试以下操作:
// Create handler for main thread where mContext is application context
mHandler = new Handler(mContext.getMainLooper());
...
// Connect to BLE device from mHandler
mHandler.post(new Runnable() {
@Override
public void run() {
    mBTGatt = mBTDevice.connectGatt(mContext, false, mGattCallback);
}
});

当然,您也可以使用Activity.runOnUiThread。来源:https://stackoverflow.com/a/23478737

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接