Android working with Bluetooth On/Off Tutorial with Example

By | August 10, 2019
Android Bluetooth Example Tutorial

What is Bluetooth in Android?

Bluetooth is a way to send or receive data between two different devices. It is exchange data with other devices wirelessly. Bluetooth is communication network protocol, which allow a devices to connect wirelessly to exchange the data with other Bluetooth devices.

Android provides Bluetooth API to perform these different operations.

Scan for other Bluetooth devices .

connect and transfer data from and to other devices.

Multiple Connection Manage. Get the list of paired devices.

What is Bluetooth Adapter Class in Android ?

BluetoothAdapter class is a 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.

Bluetooth Adapter Class use to Constants String.


Methods of BluetoothAdapter Class

static synchronized BluetoothAdapter getDefaultAdapter() : In this Method is used to return the instance of BluetoothAdapter.

boolean enable() : In this Method is used to Enable the Bluetooth adapter when if it disabled.

boolean isEnabled() : In this Method is used to return true/false if return true the bluetooth adapter is enabled.

boolean disable() : In this Method is used to Disable the Bluetooth when if it is enable.

String getName() : In this Method is used to Return the method if Bluetooth name.

boolean setName(String name) : In this Method is used to Change the Name of bluetooth.

int getState() : In this Method is used to Return the Current State of bluetooth adapter.

Set<BluetoothDevice> getBondedDevices() : In this Method is used to returns a set of paired (bonded) BluetoothDevice objects.

boolean startDiscovery() : In this Method is used to Start the Discovery.

Example of Bluetooth Enable/Disable In Android

Declared Permission in AndroidManifest.xml File Follow this Code.

Create activity_main.xml File Follow this Code.

Create File Follow this code.

Above the Example of How to Enable And Disable Bluetooth In Android.In this Example of Create Two button is On And Off When you can click on button to enable the bluetooth and then click on Off button to Disable the Bluetooth in Android.