Как отправить шестнадцатеричные значения через Bluetooth в Android - PullRequest
8 голосов
/ 07 ноября 2011

Я хочу отправить шестнадцатеричную строку в Android через Bluetooth / SPP, я попробовал это:

out = sock.getOutputStream ();

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

вотправить эту строку:

out.write(myHexString.getBytes());

но не сработало ...

любая помощь?

1 Ответ

11 голосов
/ 08 ноября 2011

проблема решена с помощью этого:

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]);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...