Chapter 18. Bluetooth

18.1. Introduction: Bluetooth

Ian Darwin


Bluetooth technology allows users to connect a variety of peripherals to a computer, tablet, or phone. Headsets, speakers, keyboards, and printers; medical devices such as glucometers and ECG machines; these are only some of the numerous types of devices that can be connected via Bluetooth. Some, such as headsets, are supported automatically by Android; the more esoteric ones will need some programming. Some of these other devices use Serial Port Protocol (SPP), which is basically an unstructured protocol that requires you to write code to format data yourself.

This chapter has recipes on how to ensure that Bluetooth is turned on, how to make your device discoverable, how to discover other devices, and how to read from and write to another device over a Bluetooth connection.[1]

A future edition of this work will provide coverage of the Bluetooth Health Device Profile (HDP) standardized by the Continua Health Alliance.

18.2. Enabling Bluetooth and Making the Device Discoverable

Rachee Singh


The application requires that the Bluetooth adapter be switched on, so you need to check if this capability is enabled. If it is not enabled, you need to prompt the user to enable Bluetooth. To allow remote devices to detect the host device, you must make the host device discoverable.


Use intents to prompt the user to enable Bluetooth and make the device discoverable.


Before performing any action with an instance ...

Get Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.