public class BluetoothFinder
extends java.lang.Object
implements javax.bluetooth.DiscoveryListener
Class to perform an inquiry for Bluetooth devices and their services.
Strategy for fast connection to a device with given device name:
- Invoke static methods searchPreknownDevice() and searchCachedDevice()
- If fails, perform an extended search by constructing a BluetoothFinder instance
with uuids = 0 (no service search)
- Retrieve Bluetooth address with RemoteDevice.getBluetoothAddress()
- Declare a connection URL string using the known service protocol, e.g.
connectionUrl = "btspp://" + address + ":1;authenticate=false;encrypt=false;master=false"
- Open a stream connection conn = (StreamConnection)Connector.open(connectionUrl)
- For data transfer open input and/or output streams with
conn.openInputStream(), conn.openOutputStream()
After an extending search, the callback method BluetoothResponser.notifyBluetoothDeviceSearch()
is called, where device search information can be retrieved. If a service search is performed, the
callback methode BluetoothResponder.notifyBluetoothServiceSearch() is called, where service search
information can be retrieved.
BluetoothFinder
(javax.bluetooth.RemoteDevice remoteDevice,
int[] uuids,
boolean isVerbose,
BluetoothResponder
responder)
Same as BluetoothFinder(RemoteDevice remoteDevice, int[] uuids,
int[] attrSet, boolean isVerbose, BluetoothResponder responder),
but only the following service attributes are retrieved:
ServiceRecordHandle (id: 0x0000)
ServiceClassIDlist (id: 0x0001)
ServiceRecordState (id: 0x0002)
ServiceID (id: 0x0003)
ProtocolDescriptorList (id: 0x0004)
Service Name (id: 0x0100)
Response will trigger the callback methods declared
in the given BluetoothResponder.
BluetoothFinder
(javax.bluetooth.RemoteDevice remoteDevice,
int[] uuids,
int[] attrSet,
boolean isVerbose,
BluetoothResponder
responder)
Initiates
service
inquiry (no prior device inquiry) from given
remote device with given UUIP integer values.
BluetoothFinder
(java.lang.String deviceName,
int[] uuids,
boolean isVerbose,
BluetoothResponder
responder)
Same as Bluetoothfinder(int[] uuids, boolean isVerbose), but search
only for the given deviceName.
BluetoothFinder
(java.lang.String deviceName,
int[] uuids,
int[] attrSet,
boolean isVerbose,
BluetoothResponder
responder)
Same as BluetoothFinder(int[] uuids, int[] attrSet, boolean isVerbose), but search
only for the given deviceName.
deviceDiscovered
(javax.bluetooth.RemoteDevice remoteDevice,
javax.bluetooth.DeviceClass deviceClass)
For internal use only.
static java.lang.String
getDeviceName
(javax.bluetooth.RemoteDevice dev)
Returns device name from given device using RemoteDevice.getFriendlyName().
static javax.bluetooth.DiscoveryAgent
getDiscoveryAgent
()
Returns the local discovery agent.
static java.lang.String
getLocalBluetoothAddress
()
Returns the local Bluetooth address, empty if no Bluetooth available.
static java.lang.String
getLocalBluetoothName
()
Returns the local Bluetooth friendly name, empty if no Bluetooth available.
static javax.bluetooth.RemoteDevice
getRemoteDevice
(java.lang.String macAddress)
Creates a Bluetooth device based on its MAC address.
static java.lang.String
getServiceName
(javax.bluetooth.ServiceRecord serviceRecord)
Returns service name from given service record.
inquiryCompleted
(int inqType)
For internal use only.
static boolean
isBluetoothSupported
()
Returns state of local Bluetooth device.
static javax.bluetooth.RemoteDevice
searchCachedDevice
(java.lang.String deviceName)
Searches for device with given name in the 'cached' database, and return it.
static javax.bluetooth.RemoteDevice
searchPreknownDevice
(java.lang.String deviceName)
Searches for device with given name in the 'preknown' database, and return it.
servicesDiscovered
(int transID,
javax.bluetooth.ServiceRecord[] serviceRecords)
For internal use only.
serviceSearchCompleted
(int transID,
int respCode)
For internal use only.
boolean isVerbose,
BluetoothResponder
responder)
Same as Bluetoothfinder(int[] uuids, boolean isVerbose), but search
only for the given deviceName. If deviceName is empty or null, the search
is done for all devices.
boolean isVerbose,
BluetoothResponder
responder)
Initiates extensive device and service inquiry with given UUIP integer values.
Typical 16-bit integer UUIDs of common services
SDP 0x0001
RFCOMM 0x0003
OBEX 0x0008
HTTP 0x000C
L2CAP 0x0100
If uuids = null, no service search is performed.
Searches only services with attribute IDs given in attrSet.
Set isVerbose = true to enable status information via VerboseWriter.
Response will trigger the callback methods declared
in the given BluetoothResponder.
-
See Also:
-
BluetoothResponder
,
UUID
,
VerboseWriter
boolean isVerbose,
BluetoothResponder
responder)
Initiates device and service search with given UUIP integer values.
Typical 16-bit integer UUIDs of common services
SDP 0x0001
RFCOMM 0x0003
OBEX 0x0008
HTTP 0x000C
L2CAP 0x0100
If uuids = null, no service search is performed.
Set isVerbose = true to enable status information via VerboseWriter.
Only the following service attributes are retrieved:
ServiceRecordHandle (id: 0x0000)
ServiceClassIDlist (id: 0x0001)
ServiceRecordState (id: 0x0002)
ServiceID (id: 0x0003)
ProtocolDescriptorList (id: 0x0004)
Service Name (id: 0x0100)
Response will trigger the callback methods declared
in the given BluetoothResponder.
-
See Also:
-
BluetoothResponder
,
UUID
,
VerboseWriter
boolean isVerbose,
BluetoothResponder
responder)
Same as BluetoothFinder(int[] uuids, int[] attrSet, boolean isVerbose), but search
only for the given deviceName. If deviceName is empty or null, the search
is done for all devices.
BluetoothFinder
public BluetoothFinder(javax.bluetooth.RemoteDevice remoteDevice,
int[] uuids,
boolean isVerbose,
BluetoothResponder responder)
Same as BluetoothFinder(RemoteDevice remoteDevice, int[] uuids,
int[] attrSet, boolean isVerbose, BluetoothResponder responder),
but only the following service attributes are retrieved:
ServiceRecordHandle (id: 0x0000)
ServiceClassIDlist (id: 0x0001)
ServiceRecordState (id: 0x0002)
ServiceID (id: 0x0003)
ProtocolDescriptorList (id: 0x0004)
Service Name (id: 0x0100)
Response will trigger the callback methods declared
in the given BluetoothResponder.
-
See Also:
-
BluetoothResponder
,
UUID
,
VerboseWriter
BluetoothFinder
public BluetoothFinder(javax.bluetooth.RemoteDevice remoteDevice,
int[] uuids,
int[] attrSet,
boolean isVerbose,
BluetoothResponder responder)
Initiates
service
inquiry (no prior device inquiry) from given
remote device with given UUIP integer values.
Typical 16-bit integer UUIDs of common services
SDP 0x0001
RFCOMM 0x0003
OBEX 0x0008
HTTP 0x000C
L2CAP 0x0100
Searches only services with attribute IDs given in attrSet.
Set isVerbose = true to enable status information via VerboseWriter.
Response will trigger the callback methods declared
in the given BluetoothResponder.
-
See Also:
-
BluetoothResponder
,
UUID
,
VerboseWriter
deviceDiscovered
public void deviceDiscovered(javax.bluetooth.RemoteDevice remoteDevice,
javax.bluetooth.DeviceClass deviceClass)
For internal use only.
Specified by:
deviceDiscovered
in interface
javax.bluetooth.DiscoveryListener
servicesDiscovered
public void servicesDiscovered(int transID,
javax.bluetooth.ServiceRecord[] serviceRecords)
For internal use only.
Specified by:
servicesDiscovered
in interface
javax.bluetooth.DiscoveryListener
getDeviceName
public static java.lang.String getDeviceName(javax.bluetooth.RemoteDevice dev)
Returns device name from given device using RemoteDevice.getFriendlyName().
Returns null if fails.
getServiceName
public static java.lang.String getServiceName(javax.bluetooth.ServiceRecord serviceRecord)
Returns service name from given service record.
Returns null, if fails.
getDiscoveryAgent
public static javax.bluetooth.DiscoveryAgent getDiscoveryAgent()
Returns the local discovery agent.
Returns null, if fails.
searchPreknownDevice
public static javax.bluetooth.RemoteDevice searchPreknownDevice(java.lang.String deviceName)
Searches for device with given name in the 'preknown' database, and return it.
Returns null, if not found or search fails because Bluetooth is not enabled.
(Under Linux searching the search for preknown devices is not supported
with Bluecove and DiscoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN)
returns always null. A hotfix by Stefan Moser is applied to read the
file of preknown devices in the kernel file system.)
searchCachedDevice
public static javax.bluetooth.RemoteDevice searchCachedDevice(java.lang.String deviceName)
Searches for device with given name in the 'cached' database, and return it.
Returns null, if not found or search fails. Under Linux this methods
returns always null, because DiscoveryAgent.retrieveDevices() is not
supported.
isBluetoothSupported
public static boolean isBluetoothSupported()
Returns state of local Bluetooth device.
-
Returns:
-
true, if Bluetooth device is installed and enabled; otherwise false
getRemoteDevice
public static javax.bluetooth.RemoteDevice getRemoteDevice(java.lang.String macAddress)
Creates a Bluetooth device based on its MAC address.
The Bluetooth address must be 12 hex characters long.
Valid characters are 0-9, a-f, and A-F. There is no preceding "0x" in the
string. For example, valid Bluetooth addresses include but are not limited to:
008037144297, 00af8300cd0b, 014bd91DA8FC.