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.
A future edition of this work will provide coverage of the Bluetooth Health Device Profile (HDP) standardized by the Continua Health Alliance.
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 ...