The S60 platform allows you to establish Bluetooth connections to other devices for sending and receiving data. The first step in making a Bluetooth connection is to discover the device you want to connect to.
Typical use cases include:
Connecting to a new Bluetooth device (uses RNotifier)
Connecting to one or more Bluetooth devices with advanced options (uses RHostResolver)
Connecting to a known/paired device (uses RBTRegistry, TBTRegistrySearch and CBTRegistryResponse)
Important implementation considerations include:
RNotifier
offers a high-level interface
implementation. If you require additional options for your application, RHostResolver
provides
a more versatile interface. For more information on the two options, see S60 Platform: Bluetooth API Developer's Guide available on Forum
Nokia.
Use of some Bluetooth configurations, such as accessing the Bluetooth registry, may require additional capabilities for your application. Note that most Bluetooth use cases can be used with the most basic signing method.
Mobility may cause breaks in Bluetooth connections if any of the connected devices moves out of the range during the connection. Your application must be prepared for unexpected connection breaks and always keep responsive to user actions.
To initialize a Bluetooth connection in your application:
Make sure that the mobile device supports Bluetooth technology using the Feature Discovery API.
Check that the Bluetooth chip is set active on the mobile device using the Bluetooth Notifier API. Launch the Bluetooth notifier through an instance of the RNotifier class.
Note: If you use the Bluetooth UI API for device discovery, the system automatically checks the Bluetooth power status. In case the Bluetooth chip is not set active, it prompts the mobile device user to switch Bluetooth on. However, applications residing on the device that receives the Bluetooth connection request still need to implement the power check.
Use one of the following three options to search for a device to connect to:
To allow a mobile device user to select a single device from a list, use the Bluetooth UI API through an instance of the RNotifier class. The RNotifier::StartNotifierAndGetResponse method launches a device selection dialog.
To open one or several Bluetooth connections with advanced options, use the RHostResolver class of the Bluetooth Sockets API. Note that this method requires you to create a UI for device selection.
Note: Since Bluetooth device search can be a lengthy operation, you need to
consider how you search for devices. For more information on device discovery
with RHostResolver
, see S60 Platform: Bluetooth API Developer's Guide available on Forum
Nokia.
To check if a previously paired device is available, use the Bluetooth Manager API for getting paired Bluetooth devices from the local Bluetooth registry. The following classes are particularly relevant:
RBTDeviceArray
(This class contains CBTDevice objects.)
It is assumed that once your application has received the list of already paired devices and selected the suitable one, it establishes a connection to the device.
Make sure that the Bluetooth device found provides the services that your application needs for transferring data. Use the methods of the CSdpAgent class of the Service Discovery Agent API. This class supports filtering, so that your application will receive a list of only those services that it is interested in.
Note: Because the Service Discovery Agent API is asynchronous, your application
needs to identify an observer object that implements the MSdpAgentNotifier class when creating an instance of CSdpAgent
.
Make sure
the following libraries are accessible to your linker when compiling your
application by including them in your mmp
file
or by editing the project properties in your IDE, depending on your build
environment:
euser.lib
(to search for a single Bluetooth
device)
esock.lib
(to search for Bluetooth devices
for point-to-multipoint connections)
btmanclient.lib
(to get a list of previously
paired Bluetooth devices)
sdpagent.lib
(to search for Bluetooth services)
For more information on transferring data to a selected Bluetooth device, see Transferring data over a Bluetooth connection.
For more information, see:
Getting a list of paired Bluetooth devices in the Forum Nokia Knowledge Base for instructions on how to get a list of devices that have already been paired
How to prompt the user to select a remote device in the Symbian OS for instructions on how to use the Bluetooth UI API to discover Bluetooth devices
How to inquire about remote devices in the Symbian OS Library for instructions on how to use the Bluetooth Sockets API to discover Bluetooth devices
Using Bluetooth Service Discovery Agent in the Symbian OS Library for instructions on how to use the Service Discovery Agent API to discover suitable Bluetooth services
Bluetooth Point to Multipoint Example provided by Forum Nokia for a reference example of how to use the Bluetooth Sockets API for discovering Bluetooth devices and services
S60 Platform: Bluetooth API Developer's Guide available on Forum Nokia for a discussion about the options you have for implementing Bluetooth applications as well as about the relevant components and classes