Inquiry is followed by service discovery, which is based on the Service Discovery Protocol (SDP)
Your application will have a particular UUID that you have associated with it. An UUID is needed in the service discovery process. The following snippet of code helps to illustrate this.
// UUID for this service: String uuidString = "50FDB90ADBFB49b3AA71D6BA308E45F3"; String params = "; // set optional parameters as needed // an RFCOMM (BTSPP) based service: String url = "btspp://localhost:" + uuidString + params; try { StreamConnectionNotifier connectionNotifier = (StreamConnectionNotifier) Connector.open(url); StreamConnection connection = (StreamConnection) connectionNotifier.acceptAndOpen(); } // send or receive messages to remote peer, etc.
A remote peer discovers the service by doing a service discovery on
one or more found devices using the method searchServices
in
class DiscoveryAgent
:
public int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException
The input parameters of the method are the set of service attributes to be retrieved for matching services, the set of UUIDs that define a matching service, the device of interest for service discovery, and a listener for handling the appropriate discovery callbacks.
An application normally performs service discovery on each found device
of interest. The Java APIs For Bluetooth (JSR-82) allow multiple simultaneous
service discovery transactions. The maximum number of concurrent service discoveries
allowed is defined by the property “bluetooth.sd.trans.max
”
(see JSR-82 specification).
An appropriate BluetoothStateException
will be thrown
if the application attempts to start more service discovery transactions than
allowed. JSR-82 does not specify how the underlying implementation performs
such transactions (for example, concurrently or sequentially). For related
information on Nokia devices, see Games Over Bluetooth: Recommendations To Game Developers.
Service discovery callbacks are made to an appropriate listener. The
listener implements the DiscoveryListener
interface,
which defines callback methods servicesDiscovered
and serviceSearchCompleted
.