开发者

How to make a bluetooth service publicly discoverable?

I try to create a MIDlet that provides a publically available service but the code below is not enough. The service is on (no exceptions) but still not discoverable.

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

the url is constructed as follows

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

After some googling i found that a code like this hould help:

        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)))开发者_Python百科;
        sr.setAttributeValue(0x0005, element);
        LocalDevice.getLocalDevice().updateRecord(sr);

but first it doesn't solve the problem and second i've got no idea what it actually does.

I use Nokia E70.

Any ideas?

Thanks in advance.


Did you try to use setDiscoverable method?


I know this question is really old, but I just ran into it and after a day of beating my head against the wall, I found the solution.

You need to set the service class ID of the service to something known:

ServiceRecord sr = LocalDevice.getLocalDevice().getRecord(service);
DataElement de = new DataElement(DataElement.DATSEQ);
DataElement uuid = new DataElement(DataElement.UUID, new UUID("1101",false));
de.addElement(uuid);
sr.setAttributeValue(0x0001, de);
LocalDevice.getLocalDevice().updateRecord(sr);

UUID 0x1101 is a serial device (I chose this arbitrarily) and attribute 0x0001 is the service class ID attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜