bluetooth UUID search with Java / bluecove

84 views Asked by At

In windows, I communicate fine with my bluetooth connected devices. I get the name and address of the device ok. But, the line

UUID[] uuids = device.getUUIDs();

… produces this error:

The method getUUIDs() is undefined for the type RemoteDevice

Code sample

import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.UUID;
//...
LocalDevice localDevice = LocalDevice.getLocalDevice();
DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
RemoteDevice[] devices = discoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN);
UUID[] uuids = device.getUUIDs();
2

There are 2 answers

0
Risto On

According to the documentation, the RemoteDevice class does not have a getUUIDs() method. I assume that in your code the device is a single member of the devices array, otherwise there might still be an error in your code.

0
Rifat Rubayatul Islam On

As already pointed out by others, there is no getUUID() method in RemoteDevice class. However, if you need the bluetooth address you can use the getBluetoothAddress() method like this:

package org.example;

import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import java.io.IOException;

public class BlueTest {
    public static void main(String[] args) throws IOException {
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
        RemoteDevice[] devices = discoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN);
        for (RemoteDevice device : devices) {
            System.out.println("Address: " + device.getBluetoothAddress());
            System.out.println("Name: " + device.getFriendlyName(false));
        }
    }
}

Hope this helps.