我将BLE设备与android应用程序连接了很多天,但是当我将android应用程序升级到API级别28时,它将在Android O +移动设备上放置12小时后开始自动断开连接。
我尝试通过更改clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) clientConfig.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE),但通过使用它,BLE设备甚至无法连接。
我无法共享我的整个代码,因为这超出了我的公司政策。
public boolean connect(final String address) {
stopDemoReadings();
if (mBluetoothAdapter == null || address == null) {
//Log.d(TAG, "BluetoothAdapter not initialized or unspecified address.");
return false;
}
// Previously connected device. Try to reconnect.
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) && mBluetoothGatt != null) {
//Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
return true;
} else {
return false;
}
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
if (device == null) {
return false;
}
// We want to directly connect to the device, so we are setting the autoConnect
// parameter to false.
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
//Log.d(TAG, "Trying to create a new connection.");
mBluetoothDeviceAddress = address;
mConnectionState = STATE_CONNECTING;
return true;
}
在断开连接时,BluetoothGATT onClientConnectionState()内部出现以下错误-status = 22 clientIf = 8。