【问题标题】:Android BLE GATT_ERROR(133) on connecting to deviceAndroid BLE GATT_ERROR(133) 连接到设备
【发布时间】:2015-05-07 18:46:14
【问题描述】:

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

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

我在BluetoothGattCallback.onConnectionStateChange 中收到带有status = 133newState = 2 的回调即使我的BLE 设备已关闭。

newState = 2 指的是BluetoothProfile.STATE_CONNECTED,这意味着我已连接到设备并且状态 = 133 是 GATT_ERROR(而不是状态 = 0 成功)

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

设备:一加一(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'

【问题讨论】:

标签: android bluetooth bluetooth-lowenergy android-bluetooth


【解决方案1】:

某些设备需要在 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。来源:https://stackoverflow.com/a/23478737

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    相关资源
    最近更新 更多