Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Hex Values via Bluetooth in Android

i want to send a hex string in android via bluetooth/SPP i tried this:

out = sock.getOutputStream();

String myHexString = Integer.toHexString(80) + " "
        + Integer.toHexString(2) + " " + Integer.toHexString(0)
        + " " + Integer.toHexString(48);

to send this String:

out.write(myHexString.getBytes());

but didn't work...

any help?

like image 865
znarf Avatar asked Nov 07 '11 13:11

znarf


1 Answers

problem solved with this:

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]);
}
like image 141
znarf Avatar answered Oct 23 '22 13:10

znarf