gpt4 book ai didi

Android 监听没有 UUID 的连接

转载 作者:搜寻专家 更新时间:2023-11-01 09:03:51 24 4
gpt4 key购买 nike

我编写了一个使用蓝牙传输数据的 Android 游戏。我从 ADK 附带的蓝牙聊天应用程序中复制了代码。我的手机好像不能连接UUID所以我想换成其他方法。我已经用

替换了我的连接方法
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);

现在我想知道如何监听这种连接?目前有阅读

tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,MY_UUID_SECURE);

但这显然需要发送 UUID。

最佳答案

感谢史密斯先生为我提供了答案。通过一些研究,我找到了另一个 StackOverflow question具有相同的主题和a good source file有了我正在寻找的解决方案。

我基本上要做的是使用 private BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 获取 BluetoothAdapter,然后监听与

的连接
Method m = adapter.getClass().getMethod("listenUsingRfcommOn", new Class[] { int.class });
BluetoothServerSocket tmp = (BluetoothServerSocket) m.invoke(adapter, 1);

关于Android 监听没有 UUID 的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362774/

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