Android在Gatt.writeDescriptor()之后执行Gatt超时
我目前正在尝试让android上的一个BLE应用程序工作。具体地说,我正在尝试拾取从iOS设备发送的BLE信号。下面是与我的问题相关的代码Android在Gatt.writeDescriptor()之后执行Gatt超时,android,bluetooth,bluetooth-lowenergy,android-bluetooth,Android,Bluetooth,Bluetooth Lowenergy,Android Bluetooth,我目前正在尝试让android上的一个BLE应用程序工作。具体地说,我正在尝试拾取从iOS设备发送的BLE信号。下面是与我的问题相关的代码 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { Log.w(tag, "State: " + newState+" status: "+ status + " (0 is success)");
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.w(tag, "State: " + newState+" status: "+ status + " (0 is success)");
if (newState == BluetoothProfile.STATE_CONNECTED) {
String intentAction = "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
final Intent intent = new Intent(intentAction);
callbackActivity.sendBroadcast(intent);
Log.w(tag, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.w(tag, "Attempting to start service discovery:" +
mConnectedGatt.discoverServices());
// Clear data to prepare for new data reading
bluetoothData.clear();
} else {
Log.w(tag, "GATT connection unsuccessful.");
restartSearch(gatt);
}
}
/**
* Called when a service has been discovered in the connected device
*/
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.w(tag, "Services Discovered! "+status);
if(gatt.getService(SERVICE_UUID)!=null){
Log.w(tag, "Not null!");
BluetoothGattCharacteristic characteristic=gatt.getService(SERVICE_UUID).getCharacteristic(CHARACTERISTC_UUID);
gatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
Log.w(tag, "Writing to descriptor: "+mConnectedGatt.writeDescriptor(descriptor));
}
else{
Log.w(tag, "Services discovered unsuccessful");
restartSearch(gatt);
}
当我激活这两个设备时,android设备总是会连接。连接总是成功的,对discoverServices()的调用总是导致对onServiceDiscovered的回调。找到了我正在搜索的特征,调用mConnectedGatt.writeDescriptor(描述符)总是返回true。但是,我的onCharacteristicChanged回调从未被调用。相反,程序在writeDescriptor调用后等待大约10秒钟,然后我得到一个对onConnectionStateChanged的调用,指定连接已丢失。这种情况95%都会发生。5%的时候,一切都很完美,我接到了onCharacteristicChanged的电话
是否有任何原因导致此超时持续发生?顺便说一句,我相信这是我的android代码中的一个问题,因为我可以在iOS设备之间完美地发送和接收这个可扩展信号 我在牛轧糖7.0上也面临同样的问题,它只发生在一个可编程设备上。同样的设备在安卓5.0和6.0上运行?有人面临过类似的问题吗?