Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 第一次通过ble传输数据后应用程序冻结_Android_Bluetooth Lowenergy - Fatal编程技术网

Android 第一次通过ble传输数据后应用程序冻结

Android 第一次通过ble传输数据后应用程序冻结,android,bluetooth-lowenergy,Android,Bluetooth Lowenergy,我正在编写一个将数据传输到远程设备(也是由我设计的)的应用程序。正在使用蓝牙低能量。总共,我需要8个变速箱,变速箱一个接一个地传送。每个后续传输在前一个传输的onCharacteristicWrite事件之后开始 问题是,在第一次传输之后,应用程序会冻结。在此时的日志中,我可以看到以下内容: D / OpenGLRenderer: eglDestroySurface = 0x71e6515eb0 D / ViewRootImpl @ 616c063 [MainActivity]: dispatc

我正在编写一个将数据传输到远程设备(也是由我设计的)的应用程序。正在使用蓝牙低能量。总共,我需要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.
V / InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@ce956af nm: com.example.example ic = null
I / InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D / BLUETOOTH: onCharacteristicWrite
此时,远程设备以0x13状态报告客户端断开连接。(确认第一次传输后)

屏幕变暗后,应用程序继续其工作,在日志中显示以下内容:

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.
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=“orientation | screenSize”并不能解决问题

PS如果有关系,那么我将MTU设置为500,但每次传输仅传输496字节

我的代码:

ch.dataCharacteristic.setValue(data.get(i));
gatt.writeCharacteristic(gatts.get(i).dataCharacteristic);
解决了。 我必须使用:

ch.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

如果服务器没有向记录发送响应。

更新:当传输的数据包大小与MTU相同时,冻结应用程序没有问题。有没有一种方法可以用一个恒定的MTU传输任意大小的数据包,而不用用零填充剩余的空间?你有没有新的线程来做这件事?也许你可以发布你的代码?使用蓝牙gatt时不需要新线程,因为操作是异步的。谢谢回复。我不会为ble创建新线程。我通过添加代码修改了我的帖子