
但是当我尝试发送大小超过1024字节的字符串时,消息不会传输.
我尝试更改下面的代码发送超过1024字节,但我没有成功.
请帮我.
阅读代码:
public voID run() { Log.i(TAG,"BEGIN mConnectedThread"); byte[] buffer = new byte[1024]; int bytes; // Keep Listening to the inputStream while connected while (true) { try { // Read from the inputStream bytes = mmInStream.read(buffer); // Send the obtained bytes to the UI Activity mHandler.obtainMessage(SmallWorld.MESSAGE_READ,bytes,-1,buffer).sendToTarget(); } catch (IOException e) { Log.e(TAG,"disconnected",e); connectionLost(); break; } } } 发送代码:
public voID write(byte[] buffer) { try { mmOutStream.write(buffer); // Share the sent message back to the UI Activity mHandler .obtainMessage(SmallWorld.MESSAGE_WRITE,buffer) .sendToTarget(); } catch (IOException e) { Log.e(TAG,"Exception during write",e); } } 打电话给:
String message="blabla";byte[] send = message.getBytes(); mChatService.write(send);解决方法 在写入之后,您可能希望刷新流以强制发送数据,因为可能是流正在缓冲数据并在发送数据之前等待更多数据.
试试..
mmOutStream.write(buffer);mmOutStream.flush();总结
以上是内存溢出为你收集整理的通过蓝牙在Android上发送长文本消息全部内容,希望文章能够帮你解决通过蓝牙在Android上发送长文本消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)