android消息发送字符串,通过蓝牙在Android上发送长文本消息

我正在使用

android:BluetoothChat的示例应用程序.

但是当我尝试发送大小超过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, -1, -1, buffer)

.sendToTarget();

} catch (IOException e) {

Log.e(TAG, "Exception during write", e);

}

}

打电话给:

String message="blabla";

byte[] send = message.getBytes();

mChatService.write(send);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值