Android的BLE GATT_ERROR(133)上的连接装置 [英] Android BLE GATT_ERROR(133) on connecting to device
问题描述
我试图连接到使用MAC地址的BLE设备。
BluetoothDevice类设备= bluetoothAdapter.getRemoteDevice(rememberedDeviceAddress)
bluetoothDevice.connectGatt(背景下,假的,bluetoothGattCallback);
我得到一个回调BluetoothGattCallback.onConnectionStateChange与状态= 133和newState = 2的甚至当我BLE装置处于关闭状态。
newState = 2是指BluetoothProfile.STATE_CONNECTED这意味着我正在连接到装置和状态= 133是GATT_ERROR(而不是状态= 0 SUCCESS)
我不明白在无法注册回调错误。
设备:一加一(Android 4.4系统)
这是什么可能导致此问题的任何指针将是有益的。
请注意:问题不所有的设备上发生的。一切似乎是工作在Nexus 5细跟的是Android 5.0
请找到堆栈跟踪如下:
13 03-06:00:11.994:D / BluetoothGatt(26771):registerApp()
03-06 13:00:11.994:D / BluetoothGatt(26771):registerApp() - UUID = UUID来这里
03-06 13:00:12.004:D / BluetoothGatt(26771):onClientRegistered() - 状态= 0 clientIf = 5
03-06 13:00:42.004:D / BluetoothGatt(26771):onClientConnectionState() - 状态= 133 clientIf = 5设备='设备ID来这里
某些设备需要蓝牙LE的互动要在UI线程上运行。因此,我建议想是这样的:
//创建主线程处理器,其中mContext是应用程序上下文
mHandler =新处理程序(mContext.getMainLooper());
...
//连接到从mHandler BLE装置
mHandler.post(新的Runnable(){
@覆盖
公共无效的run(){
mBTGatt = mBTDevice.connectGatt(mContext,假的,mGattCallback);
}
});
当然,你可以使用Activity.runOnUiThread为好。来源: http://stackoverflow.com/a/23478737
I am trying to connect to a BLE device using the MAC address.
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.
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)
I do not get the Failed to register callback error.
Device : One plus one (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
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. 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. Source: http://stackoverflow.com/a/23478737
这篇关于Android的BLE GATT_ERROR(133)上的连接装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!