连接到设备时出现Android BLE GATT_错误(133)
我正在尝试使用MAC地址连接到可扩展设备连接到设备时出现Android BLE GATT_错误(133),android,bluetooth,bluetooth-lowenergy,android-bluetooth,Android,Bluetooth,Bluetooth Lowenergy,Android Bluetooth,我正在尝试使用MAC地址连接到可扩展设备 BluetoothDevice device = bluetoothAdapter.getRemoteDevice(rememberedDeviceAddress) bluetoothDevice.connectGatt(context, false, bluetoothGattCallback); 我在BluetoothGattCallback.onConnectionStateChange中收到一个回调,状态为status=133和newState
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(rememberedDeviceAddress)
bluetoothDevice.connectGatt(context, false, bluetoothGattCallback);
我在BluetoothGattCallback.onConnectionStateChange
中收到一个回调,状态为status=133
和newState=2
,即使我的BLE设备已关闭。
newState=2指的是Bluetooth配置文件。STATE\u CONNECTED表示我已连接到设备,status=133表示GATT\u错误(而不是status=0 SUCCESS)
我没有收到注册回调失败的错误
设备:一加一(安卓4.4)
任何关于什么可能导致此问题的指针都会有所帮助
注意:问题并非发生在所有设备上。在装有安卓5.0的Nexus5上,一切似乎都运转良好
请在堆栈跟踪下方找到:
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'
某些设备需要在UI线程上运行蓝牙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。资料来源:看看这个问题的建议答案:你能想出这个答案吗?我也有同样的问题。