gpt4 book ai didi

android - 如何在 Android 中通过蓝牙发送十六进制值

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:52 31 4
gpt4 key购买 nike

我想通过蓝牙/SPP 在 android 中发送一个十六进制字符串我试过这个:

out = sock.getOutputStream();

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

发送这个字符串:

out.write(myHexString.getBytes());

但是没用...

有什么帮助吗?

最佳答案

问题解决了:

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]);
}

关于android - 如何在 Android 中通过蓝牙发送十六进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037414/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com