Bonding with Bluetooth devices in Android
In today's video our topic is Bonding with Bluetooth Devices in Android.
Once you enable the Bluetooth, you can get a list of paired device by calling getBondedDevices() method. It returns a set of bluetooth devices
There are different methods of bluetooth adaptor class like enable(), isEnabled(),
setName(String name), getState(), startDiscovery() etc...
We need to use one Client Server Mechanism to transfer files from one bluetooth to another.
The server and client are considered connected to each other when they each have a connected Bluetooth Socket on the same RFCOMM channel. At this point each device can obtain input and output streams and data transfer can begin.
The service device and the client device each obtain the required Bluetooth socket in different ways. The server will receive it when an incoming connection is accepted. The client will receive it when it opens an RFCOMM channel to the server.
The purpose of the server socket is to listen for incoming connection requests and when one is accepted, provide a connected BluetoothSocket. If you over data communication task then disconnect it.
The steps for connecting Server Socket are as follows :
- Get a BluetoothServerSocket by calling the listenUsingRfcommWithServiceRecord(String,UUID).
- Start listening for connection requests by calling accept().
- Unless you want to accept additional connections, call close().