我正在开发其他硬件设备的android app
接收big file
(4M左右)。该器件1382400 bps
发送数据,但我的Android程序只能接收400K
。数据读取的代码是在一个独立的线程,什么也不做,但是从InputStream
阅读并计算读取的字节。这是我的代码片段:
try {
socket = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
socket.connect();
InputStream is = socket.getInputStream();
byte[] buf = new byte[1024];
int byteRead ;
while ((byteRead = is.read(buf)) > 0) {
totalBytes += byteRead;
Log.v(LOG_TAG, "read byte:" + totalBytes);
}
} catch (IOExcepiton e) {
Log.e(LOG_TAG, "Connect to bluetooth device failed.", e);
return null;
}
我已经做了很多的实验,试图找出问题:
android 6.0
到android 8.0
),它能够接收数据的400K ~ 500K
当发送者发送4M
数据。显然,90%的数据传输过程中丢失。2K
多,Android是能够接收完全。它开始丢失数据的第一2K
包后。baudrate(1382400)
,但每50ms
传输入睡后1K
,机器人也能够完全接收整个4M
文件。4M
文件传输到另一台机器人,它需要大约而不丢失数据30s
。4号表示的Android原生支持高速率传输(> 1Mbps
),但我不能在我自己的代码来实现。所述远程设备使用HC-06
串行到bluetooth
适配器其中文档可以发现here。该文件显示适配器支持1.3M
bps的速率都在串行和bluetooth
在空气中。
我搜索地段计算器和谷歌有关Android bluetooth
传输速率和低级别buffer
大小没有进一步的信息文章。
谁能给我如何获得android
高传输速率一些建议吗?非常感谢。
请考虑使用一个缓冲流。按字节读取字节,并将其打印到日志消息的方式TOOOO缓慢。有了这个,你绑定字节读你的调试输出的速度的快慢。
这个问题也可以复制到Android Bluetooth Serial RFCOMM low baud rate / slow transmission