Я использую пример приложения от 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);