M
M
MGriboedoff2015-08-19 17:02:18
Bluetooth
MGriboedoff, 2015-08-19 17:02:18

Android, bluetooth, HEX, send multiple bytes in one packet?

private boolean connected = false;
private BluetoothSocket sock;
private InputStream in;
private OutputStream out;

zee = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(
        "XX:XX:XX:XX:XX:XX");
    m = zee.getClass().getMethod("createRfcommSocket",
        new Class[] { int.class });
    sock = (BluetoothSocket) m.invoke(zee, Integer.valueOf(1));
    sock.connect();
    in = sock.getInputStream();
    out = sock.getOutputStream();

char[] test = { 0x55, 0x0, 0x0, 0x0, 0x0, 0x50, 0x2, 0x0,
        0x30, 0xD7 };

for(int k=0; k < test.lenght; k++){
new DataOutputStream(sock.getOutputStream()).writeByte(test[k]);
}




for(int k=0; k < test.lenght; k++){
new DataOutputStream(sock.getOutputStream()).writeByte(test[k]);
}

This great code sends byte by byte, but I need to send everything in one packet.
How can I send data to HEX not byte by byte, but in one packet?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svd71, 2015-08-19
@MGriboedoff

Have a look at other OutputStream methods:
docs.oracle.com/javase/7/docs/api/java/io/OutputSt...
write(byte [] b) - Writes b.length bytes from the specified byte array to this output stream .
write(byte [] b, int off, int len) - Writes len bytes from the specified byte array starting at offset off to this output stream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question