Initializing a Bluetooth connection

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:

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.

Discovering a Bluetooth device

To initialize a Bluetooth connection in your application:

  1. Make sure that the mobile device supports Bluetooth technology using the Feature Discovery API.

  2. 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.

  3. 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:

      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.

  4. 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.

  5. 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.

Additional information on initializing Bluetooth connections

For more information, see: