Java Reference
In-Depth Information
In Table 12-2, you can see that the UUID of the service corresponds to ServiceRecord
attribute ID 0x0003 . There are a very large number of possible attributes. For the entire list of
attributes, their descriptions, and data types, see the Bluetooth “Assigned Numbers” document
( http://www.bluetooth.org/assigned-numbers/sdp.htm ).
Incidentally, the list of attributes in Table 12-2 is exactly the mandatory attributes that
every ServiceRecord must have. They are also the default attributes that will be fetched during
service discovery via a searchServices() method call.
The ServiceRecord class has the following methods for manipulation of attributes:
int[] getAttributeIDs(); .
DataElement getAttributeValue(int attrID);
boolean setAttributeValue(int attrID, DataElement attrValue);
The getAttributeIDs() method returns all the attributes that can be obtained via the
getAttributeValue() call. Not all possible attributes are available; availability depends on the
set of attributes specified during service discovery. If you want to update a ServiceRecord ,
use setAttributeValue() . You must call updateRecord() on the LocalDevice instance for the
change to be reflected in the SDDB. See the next section for a description of how to place a
ServiceRecord into the SDDB in the first place.
The GCF connection string associated with a ServiceRecord (that is, an available service)
can be obtained via a call to the getConnectionURL() method:
String getConnectionURL(int requiredSecurity, boolean mustBeMaster);
If the ServiceRecord is result of discovery, you can also obtain a reference to the
RemoteDevice by calling this method:
RemoteDevice getHostDevice();
Creating a Bluetooth Service
To offer a service over Bluetooth, your application first needs to register a ServiceRecord in the
SDDB. The way you create and register a ServiceRecord is coupled with the GCF. First, you
need to create a StreamConnectionNotifier (similar to a ServerSocketConnection ). For example,
the following call to Connector.open() will create a StreamConnectionNotifier and the corre-
sponding ServiceRecord .
StreamConnectionNotifier myNotifier = (StreamConnectionNotifier)
Connector.open("btspp://localhost: BAE0D0C0B0A000955570605040302010;name=Dating
Service;authorize=false"
);
The protocol specification for the GCF connection string is “btspp://” for the Bluetooth
Serial Port Profile. This is a Bluetooth profile that all JSR 82-compliant devices must implement,
and it provides RS232 serial port emulation. Underneath the hood, a high-level stream-based
protocol called RFCOMM is working on top of a lower-level packet-based protocol called L2CAP.
Search WWH ::




Custom Search