私はアンドロイド:BluetoothChatのサンプルアプリを使用しています。 しかし、文字列を送信しようとすると、1024バイトを超えるサイズのメッセージは転送されません。 以下のコードを1024バイト以上送信するように変更しようとしていますが、これでは成功しません。 私を助けてください。Bluetoothでアンドロイドで長いテキストメッセージを送信
読むコード:
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);
どうしたらいいですか? –
エラーメッセージが表示されません。バッファのサイズを変更しても1024バイトの文字列(文字列をカットします)を送信します。 – Beno
ここで、文字列を送信するコードは –