The first step in a networked Bluetooth application is often to discover other devices that are in range.
Note: The S60 3rd Edition FP 1 implementation of the Bluetooth API does not support using LIAC because the Symbian Bluetooth stack does not support the operation. Also changing the discovery mode is not supported at all.
A MIDlet application can use either the GIAC or the LIAC form of inquiry for device inquiry. A general inquiry is used to find all nearby GIAC-discoverable devices for an unlimited amount of time.
An alternative form is to use the limited form of inquiry. The Java APIs For Bluetooth specification may give the impression that when LIAC is used, the device is only discoverable for a limited amount of time (for example, one minute) and the device will automatically revert back to its previous discoverable mode after that time has expired. However when LIAC is used in S60 and Series 40 devices, it should remain in use until the MIDlet changes this (for example, to GIAC) or until the MIDlet terminates. This approach is easier for developers and end users to understand and utilize. Use of LIAC for the device inquiry phase can be especially useful when there are large numbers of GIAC-discoverable devices nearby.
The LocalDevice
class methods getDiscoverable
and setDiscoverable
are
used to get and set the discoverable mode for a device.
The DiscoveryAgent
class provides the methods needed
for performing device inquiry. Device inquiry is performed using the method startInquiry
.
Callbacks are made to an appropriate handler that implements the DiscoveryListener
interface,
via the methods deviceDiscovered
(for each device found)
and inquiryComplete
(when the device inquiry process
has ended).
Your application should also perform filtering of found devices based
on their Class of Device (COD), before performing a service search on them.
You will want to perform service searches only on found devices whose COD
makes sense for the service. For example, if you are writing a game MIDlet,
you can skip doing a service search on all the headsets, car kits, digital
pens, and probably most laptops that are found. The DiscoveryListener
interface’s
callback method deviceDiscovered
has a parameter called DeviceClass
that
can be used for such filtering.
As an alternative to performing device inquiry, an application might
use a list of preknown or cached devices. The method retrieveDevices
of
the DiscoveryAgent
class can be used to request a list
of known RemoteDevice
objects. However the method retrieveDevices
does
not provide the COD, nor does class RemoteDevice
provide
that information. (See the previous paragraph about the importance of filtering
devices based on their COD.)