Sunday, February 4, 2018

Using BlueTooth in Android

Bluetooth is a way to send or receive data between two different devices. Android platform includes support for the Bluetooth framework that allows a device to wirelessly exchange data with other Bluetooth devices.
Android provides Bluetooth API to perform these different operations.
  • Scan for other Bluetooth devices
  • Get a list of paired devices
  • Connect to other devices through service discovery
Android provides BluetoothAdapter class to communicate with Bluetooth. Create an object of this calling by calling the static method getDefaultAdapter(). Its syntax is given below.

private BluetoothAdapter BA;
BA = BluetoothAdapter.getDefaultAdapter();
In order to enable the Bluetooth of your device, call the intent with the following Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is.
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);       
Apart from this constant, there are other constants provided the API , that supports different tasks. They are listed below

1 comment:

  1. Hi,
    Thanks for sharing the information with us it was very informative. https://hangup.in

    ReplyDelete