android - BLE:三星手机上的 onConnectionStateChange 状态 8
问题描述
我正在开发一个心率监测应用程序,我正在从 BLE 设备读取数据,对于所有其他手机都没有问题,但对于三星手机,如 Note 8,它使用蓝牙版本 5.0 一段时间后自动断开连接,我正在获取状态8
代码 :
对于连接
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mGattClient = device.connectGatt(this, false, mGattCallbacks, TRANSPORT_LE)
} else {
mGattClient = device.connectGatt(this, false, mGattCallbacks)
}
//连接状态改变
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// this sleep is here to avoid TONS of problems in BLE, that occur whenever we start
// service discovery immediately after the connection is established
mGattClient?.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
Log.d(TAG,"Disconnected status"+ status)
}
}
}
// New services discovered
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
when (status) {
BluetoothGatt.GATT_SUCCESS -> mListener?.deviceConnected(MESSAGE_CONNECTED, status)
else -> Log.w("BLE", "onServicesDiscovered received: $status")
}
}
我已经在谷歌问题跟踪器上发布了这个
解决方案
此问题与 Android 操作系统本身或您的软件无关。根据蓝牙规范,错误代码 8 表示连接超时。这意味着手机中的蓝牙硬件失去了与设备的连接。主要有三个原因:天线/无线电接收不良,两个设备之间的时钟漂移导致它们失去同步,调度冲突过多(如果您有多个连接)。
您是否觉得您的 Note 8 的性能明显低于其他手机,请将问题报告发送给三星。
推荐阅读
- java - maven,将非排除的 jar 复制到文件夹
- python - 在 PyTorch 中进行部分训练后添加样本
- hash - 密码长度与 DOS 攻击
- c# - 有没有办法使用交互器事件在统一 XR 中激活按钮按下
- python - 使用 XLNet 进行情绪分析 - 设置正确的重塑参数
- mysql - 按年、半年、四个月、季度、双月和每月分组 MYSQL
- powershell - citrix 许可证服务器中到期日期的正确格式是什么?
- javascript - 等待元素加载然后渲染数据(vue.JS)
- openmdao - Dymos 约束对参数的依赖
- amazon-web-services - Dotnet Core AWS Lambda 用于 Cognito 确认后触发器完成