ch.aplu.bluetooth
Class BluetoothFinder

java.lang.Object
  extended by ch.aplu.bluetooth.BluetoothFinder
All Implemented Interfaces:
javax.bluetooth.DiscoveryListener

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.


Field Summary
 
Fields inherited from interface javax.bluetooth.DiscoveryListener
INQUIRY_COMPLETED, INQUIRY_ERROR, INQUIRY_TERMINATED, SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_DEVICE_NOT_REACHABLE, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS, SERVICE_SEARCH_TERMINATED
 
Constructor Summary
BluetoothFinder(int[] uuids, boolean isVerbose, ch.aplu.bluetooth.BluetoothResponder responder)
          Initiates device and service search with given UUIP integer values.
BluetoothFinder(int[] uuids, int[] attrSet, boolean isVerbose, ch.aplu.bluetooth.BluetoothResponder responder)
          Initiates extensive device and service inquiry with given UUIP integer values.
BluetoothFinder(java.lang.String deviceName, int[] uuids, boolean isVerbose, ch.aplu.bluetooth.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, ch.aplu.bluetooth.BluetoothResponder responder)
          Same as Bluetoothfinder(int[] uuids, int[] attrSet, boolean isVerbose), but search only for the given deviceName.
 
Method Summary
 void 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 getServiceName(javax.bluetooth.ServiceRecord serviceRecord)
          Returns service name from given service record.
 void inquiryCompleted(int inqType)
          For internal use only.
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.
 void servicesDiscovered(int transID, javax.bluetooth.ServiceRecord[] serviceRecords)
          For internal use only.
 void serviceSearchCompleted(int transID, int respCode)
          For internal use only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BluetoothFinder

public BluetoothFinder(java.lang.String deviceName,
                       int[] uuids,
                       boolean isVerbose,
                       ch.aplu.bluetooth.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.


BluetoothFinder

public BluetoothFinder(int[] uuids,
                       int[] attrSet,
                       boolean isVerbose,
                       ch.aplu.bluetooth.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

BluetoothFinder

public BluetoothFinder(int[] uuids,
                       boolean isVerbose,
                       ch.aplu.bluetooth.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

BluetoothFinder

public BluetoothFinder(java.lang.String deviceName,
                       int[] uuids,
                       int[] attrSet,
                       boolean isVerbose,
                       ch.aplu.bluetooth.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.

Method Detail

deviceDiscovered

public void deviceDiscovered(javax.bluetooth.RemoteDevice remoteDevice,
                             javax.bluetooth.DeviceClass deviceClass)
For internal use only.

Specified by:
deviceDiscovered in interface javax.bluetooth.DiscoveryListener

inquiryCompleted

public void inquiryCompleted(int inqType)
For internal use only.

Specified by:
inquiryCompleted 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

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
For internal use only.

Specified by:
serviceSearchCompleted 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.


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.