gpt4 book ai didi

java - 如何使蓝牙服务可公开发现?

转载 作者:行者123 更新时间:2023-12-01 05:58:52 24 4
gpt4 key购买 nike

我尝试创建一个提供公开可用服务的 MIDlet,但下面的代码还不够。该服务已开启(无一异常(exception)),但仍然无法发现。

public StreamConnection waitForConnection() throws IOException {

if (this.notifier == null) {
// Create a server connection (a notifier)
this.notifier = (StreamConnectionNotifier) Connector.open(serviceURL);
}
return this.notifier.acceptAndOpen();
}

url构造如下

private final static String serviceURL = "btspp://localhost:" + servieceUUID +
";name=" + serviceName + ";authenticate=false;master=false;encrypt=false";

经过一番谷歌搜索后,我发现这样的代码会有帮助:

        final ServiceRecord sr = LocalDevice.getLocalDevice().getRecord(this.notifier);
//Public browse group UUID
final DataElement element = new DataElement(DataElement.DATSEQ);
element.addElement(new DataElement(DataElement.UUID, new UUID(0x1002)));
sr.setAttributeValue(0x0005, element);
LocalDevice.getLocalDevice().updateRecord(sr);

但首先它不能解决问题,其次我不知道它实际上做了什么。

我使用诺基亚 E70。

有什么想法吗?

提前致谢。

最佳答案

您是否尝试使用 setDiscoverable方法?

关于java - 如何使蓝牙服务可公开发现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1879730/

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