public class ServiceRecord
extends java.lang.Object
ServiceRecord
class describes characteristics of a Bluetooth
service. A ServiceRecord
contains a set of service attributes, where
each service attribute is an (ID, value) pair. A Bluetooth attribute
ID is a 16-bit unsigned integer, and an attribute value is a
DataElement
.
The structure and use of service records is specified by the Bluetooth specification in the Service Discovery Protocol (SDP) document. Most of the Bluetooth Profile specifications also describe the structure of the service records used by the Bluetooth services that conform to the profile.
An SDP Server maintains a Service Discovery Database (SDDB) of service records that describe the services on the local device. Remote SDP clients can use the SDP to query an SDP server for any service records of interest. A service record provides sufficient information to allow an SDP client to connect to the Bluetooth service on the SDP server's device.
ServiceRecords
are made available to a client application via an argument
of the DiscoveryListener.servicesDiscovered(int, totalcross.io.device.bluetooth.ServiceRecord[])
method
of the DiscoveryListener
interface.
ServiceRecords
are available to server applications via the method
totalcross.io.device.bluetooth.LocalDevice#getRecord(totalcross.io.Connection)
.
There might be many service attributes in a service record, and the SDP
protocol makes it possible to specify the subset of the service
attributes that an SDP client wants to retrieve from a remote service
record. The ServiceRecord
interface treats certain service attribute
IDs as default IDs, and, if present, these service attributes are
automatically retrieved during service searches.
The Bluetooth Assigned Numbers document ( http://www.bluetooth.org/assigned-numbers/sdp.htm) defines a large number of service attribute IDs. Here is a subset of the most common service attribute IDs and their types.
Attribute Name | Attribute ID | Attribute Value Type |
---|---|---|
ServiceRecordHandle | 0x0000 | 32-bit unsigned integer |
ServiceClassIDList | 0x0001 | DATSEQ of UUIDs |
ServiceRecordState | 0x0002 | 32-bit unsigned integer |
ServiceID | 0x0003 | UUID |
ProtocolDescriptorList | 0x0004 | DATSEQ of DATSEQ of UUID and optional parameters |
BrowseGroupList | 0x0005 | DATSEQ of UUIDs |
LanguageBasedAttributeIDList | 0x0006 | DATSEQ of DATSEQ triples |
ServiceInfoTimeToLive | 0x0007 | 32-bit unsigned integer |
ServiceAvailability | 0x0008 | 8-bit unsigned integer |
BluetoothProfileDescriptorList | 0x0009 | DATSEQ of DATSEQ pairs |
DocumentationURL | 0x000A | URL |
ClientExecutableURL | 0x000B | URL |
IconURL | 0x000C | URL |
VersionNumberList | 0x0200 | DATSEQ of 16-bit unsigned integers |
ServiceDatabaseState | 0x0201 | 32-bit unsigned integer |
The following table lists the common string-valued attribute ID offsets used in a
ServiceRecord
. These offsets must be added to a base value to obtain the actual
service ID. (For more information, see the Service Discovery Protocol Specification
located in the Bluetooth Core Specification.
Attribute Name | Attribute ID Offset | Attribute Value Type |
---|---|---|
ServiceName | 0x0000 | String |
ServiceDescription | 0x0001 | String |
ProviderName | 0x0002 | String |
Modifier and Type | Field and Description |
---|---|
static int |
AUTHENTICATE_ENCRYPT
Authentication and encryption are required for connections to this service.
|
static int |
AUTHENTICATE_NOENCRYPT
Authentication is required for connections to this service, but not encryption.
|
static int |
NOAUTHENTICATE_NOENCRYPT
Authentication and encryption are not needed on a connection to this service.
|
Modifier and Type | Method and Description |
---|---|
DataElement |
getAttributeValue(int attrID)
Returns the value of the service attribute ID provided it is present in the service record, otherwise this method
returns null.
|
java.lang.String |
getConnectionURL()
Returns a string including optional parameters that can be used by a client to connect to the service described by
this ServiceRecord.
|
java.lang.String |
getConnectionURL(int requiredSecurity,
boolean mustBeMaster)
Returns a String including optional parameters that can be used by a client to connect to the service described by
this ServiceRecord.
|
RemoteDevice |
getHostDevice()
Returns the remote Bluetooth device that populated the service record with attribute values.
|
public static final int NOAUTHENTICATE_NOENCRYPT
getConnectionURL()
method.
NOAUTHENTICATE_NOENCRYPT
is set to the constant value 0x00 (0).
public static final int AUTHENTICATE_NOENCRYPT
getConnectionURL()
method.
AUTHENTICATE_NOENCRYPT
is set to the constant value 0x01 (1).
public static final int AUTHENTICATE_ENCRYPT
getConnectionURL()
method.
AUTHENTICATE_ENCRYPT
is set to the constant value 0x02 (2).
public RemoteDevice getHostDevice()
public DataElement getAttributeValue(int attrID)
attrID
- the attribute whose value is to be returnedjava.lang.IllegalArgumentException
- if attrID is negative or greater than or equal to 216public java.lang.String getConnectionURL()
public java.lang.String getConnectionURL(int requiredSecurity, boolean mustBeMaster)
requiredSecurity
- determines whether authentication or encryption are required for a connectionmustBeMaster
- true indicates that this device must play the role of master in connections to this service; false
indicates that the local device is willing to be either the master or the slavejava.lang.IllegalArgumentException
- if requiredSecurity is not one of the constants NOAUTHENTICATE_NOENCRYPT, AUTHENTICATE_NOENCRYPT, or
AUTHENTICATE_ENCRYPTNOAUTHENTICATE_NOENCRYPT