android - 通过 ble 进行第一次数据传输后应用程序冻结
问题描述
我正在编写一个将数据传输到远程设备(也是我设计的)的应用程序。正在使用低功耗蓝牙。总共,我需要 8 次传输,传输一个接一个。每个后续传输都在前一个的 onCharacteristicWrite 事件之后开始。
问题是在第一次传输后,应用程序冻结了。此时在日志中,我可以看到以下内容:
D / OpenGLRenderer: eglDestroySurface = 0x71e6515eb0
D / ViewRootImpl @ 616c063 [MainActivity]: dispatchDetachedFromWindow
D / InputEventReceiver: channel '1737a41 com.example.example / com.example.example.MainActivity (client)' ~ Disposing input event receiver.
channel '1737a41 com.example.example / com.example.example.MainActivity (client)' ~ NativeInputEventReceiver.
D / ViewRootImpl @ c8adac [MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
E / ViewRootImpl: sendUserActionEvent () returned.
此时远端设备上报客户端断线,状态为0x13。(构象第一次传输后)。
屏幕变暗后,应用程序继续工作,日志如下:
V / InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@ce956af nm: com.example.example ic = null
I / InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D / BLUETOOTH: onCharacteristicWrite
该应用程序重新连接到设备并传输另一条数据。远程设备确认收到数据。
由于数据是有时间限制的,因此这是传输结束的地方。请告诉我如何解决应用程序冻结的问题?
三星智能手机,添加“android:configChanges =” screenSize"" 不能解决问题。
PS 如果有关系,那么我将 MTU 设置为 500,但我每次传输只传输 496 个字节。
我的代码:
ch.dataCharacteristic.setValue(data.get(i));
gatt.writeCharacteristic(gatts.get(i).dataCharacteristic);
解决方案
解决了。我必须使用:
ch.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
如果服务器没有向记录发送响应。
推荐阅读
- publish-subscribe - Fiware Orion Context Broker-一段时间后发送通知
- wordpress - wordpress 5.6 版在帖子/页面编辑时隐藏了后端管理界面的左栏
- google-cloud-platform - Cloud Data Fusion 触发管道 - 重用已配置的 Dataproc 集群
- android - Mi App Store 声称 Play 应用签名存在应用问题
- powershell - Get-PnPProvisioningTemplate 未被识别为 cmdlet 的名称
- javascript - 无法使用 CSS 过滤器在画布上重绘图像
- reactjs - 未处理的拒绝(TypeError):history.pushState 不是函数
- javascript - 如何在 Javascript 中保留消息值
- laravel - 如何在 laravel-mix 期间减小 vscode 中的 notify-send 大小
- google-sheets - 需要根据单元格值添加行并从上面复制粘贴数据并转置它