Android Bluetooth Tutorial
Bluetooth is a way to exchange data with other devices wirelessly. Android provides Bluetooth API to perform several tasks such as:
Android Bluetooth API
The android.bluetooth package provides a lot of interfaces classes to work with bluetooth such as:
By the help of BluetoothAdapter class, we can perform fundamental tasks such as initiate device discovery, query a list of paired (bonded) devices, create a BluetoothServerSocket instance to listen for connection requests etc.
Constants of BluetoothAdapter class
BluetoothAdapter class provides many constants. Some of them are as follows:
Methods of BluetoothAdapter class
Commonly used methods of BluetoothAdapter class are as follows:
Android Bluetooth Example: enable, disable and make discovrable bluetooth programmatically
You need to write few lines of code only, to enable or disable the bluetooth.
Drag one textview and three buttons from the pallete, now the activity_main.xml file will like this:
You need to provide following permissions in AndroidManifest.xml file.
The full code of AndroidManifest.xml file is given below.
Let's write the code to enable, disable and make bluetooth discoverable.
You need to run it on the real device (e.g. mobile) to test the application.
Next topics of android bluetooth tutorial: