简体   繁体   English

关于连接设备的Android BLE GATT_ERROR(133)

[英]Android BLE GATT_ERROR(133) on connecting to device

I am trying to connect to a BLE device using the MAC address. 我正在尝试使用MAC地址连接到BLE设备。

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

I get a callback in BluetoothGattCallback.onConnectionStateChange with status = 133 and newState = 2 even when my BLE device is switched off. 即使我的BLE设备关闭,我BluetoothGattCallback.onConnectionStateChange收到status = 133newState = 2的回调

newState = 2 refers to BluetoothProfile.STATE_CONNECTED which means that i am connected to the device and status = 133 is GATT_ERROR (instead of status = 0 SUCCESS) newState = 2指的是BluetoothProfile.STATE_CONNECTED ,这意味着我连接到设备并且status = 133是GATT_ERROR(而不是status = 0 SUCCESS)

I do not get the Failed to register callback error. 我没有得到注册回调错误的失败

Device : One plus one (Android 4.4) 设备:一加一(Android 4.4)

Any pointers on what might be causing this issue would be helpful. 任何可能导致此问题的指针都会有所帮助。

Note: Issue does not happen on all device. 注意:问题不会发生在所有设备上。 Everything seems to be working fine on Nexus 5 with Android 5.0 在Android 5.0的Nexus 5上,一切似乎都运行良好

Please find below the stack trace: 请在下面找到堆栈跟踪:

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'

Certain devices require Bluetooth LE interactions to be run on the UI thread. 某些设备需要在UI线程上运行蓝牙LE交互。 So I would recommend trying something like this: 所以我建议尝试这样的事情:

// 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);
}
});

Of course you could use Activity.runOnUiThread as well. 当然你也可以使用Activity.runOnUiThread。 Source: https://stackoverflow.com/a/23478737 资料来源: https//stackoverflow.com/a/23478737

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM