Bluetooth is a way to exchange data with other devices wirelessly. Android provides Bluetooth API to perform several tasks such as:

  • scan bluetooth devices
  • connect and transfer data from and to other devices
  • manage multiple connections etc.

Android Bluetooth API

The android.bluetooth package provides a lot of interfaces classes to work with bluetooth such as:

  • BluetoothAdapter
  • BluetoothDevice
  • BluetoothSocket
  • BluetoothServerSocket
  • BluetoothClass
  • BluetoothProfile
  • BluetoothProfile.ServiceListener
  • BluetoothHeadset
  • BluetoothA2dp
  • BluetoothHealth
  • BluetoothHealthCallback
  • BluetoothHealthAppConfiguration


BluetoothAdapter class

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:

  • static synchronized BluetoothAdapter getDefaultAdapter() returns the instance of BluetoothAdapter.
  • boolean enable() enables the bluetooth adapter if it is disabled.
  • boolean isEnabled() returns true if the bluetooth adapter is enabled.
  • boolean disable() disables the bluetooth adapter if it is enabled.
  • String getName() returns the name of the bluetooth adapter.
  • boolean setName(String name) changes the bluetooth name.
  • int getState() returns the current state of the local bluetooth adapter.
  • Set<BluetoothDevice> getBondedDevices() returns a set of paired (bonded) BluetoothDevice objects.
  • boolean startDiscovery() starts the discovery process.

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:

File: activity_main.xml

Provide Permission

You need to provide following permissions in AndroidManifest.xml file.


The full code of AndroidManifest.xml file is given below.

File: AndroidManifest.xml

Activity class

Let’s write the code to enable, disable and make bluetooth discoverable.

package com.example.bluetooth;  
import android.os.Bundle;  
import android.view.Menu;  
import android.bluetooth.BluetoothAdapter;  
import android.content.Context;  
import android.content.Intent;  
import android.os.Bundle;  
import android.util.Log;  
import android.view.View;  
import android.widget.Button;  
import android.widget.TextView;  
import android.widget.Toast;  
public class MainActivity extends Activity {  
      private static final int REQUEST_ENABLE_BT = 0;  
      private static final int REQUEST_DISCOVERABLE_BT = 0;  
    protected void onCreate(Bundle savedInstanceState) {  
    final TextView out=(TextView)findViewById(;  
    final Button button1 = (Button) findViewById(;  
    final Button button2 = (Button) findViewById(;  
    final Button button3 = (Button) findViewById(;  
    final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();  
    if (mBluetoothAdapter == null) {  
       out.append("device not supported");  
    button1.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v) {  
            if (!mBluetoothAdapter.isEnabled()) {  
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);  
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);  
    button2.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View arg0) {  
            if (!mBluetoothAdapter.isDiscovering()) {  
                  //out.append("MAKING YOUR DEVICE DISCOVERABLE");  
                   Toast.makeText(getApplicationContext(), "MAKING YOUR DEVICE DISCOVERABLE",  
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);  
                startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);  
    button3.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View arg0) {     
            //out.append("TURN_OFF BLUETOOTH");  
            Toast.makeText(getApplicationContext(), "TURNING_OFF BLUETOOTH", Toast.LENGTH_LONG);  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(, menu);  
        return true;