How to Programmatically Scan or Discover Android Bluetooth Devices

Through Android Bluetooth API, developers can access most of bluetooth functionalities and let the applications wirelessly connect to bluetooth devices. Before connecting to a device, an application must discover or scan available bluetooth devices, request pairing and connect to the device.

android bluetooth discovery    android bluetooth scanning

(apk + source code at the bottom of this post)

To discover a device, first get the bluetooth adapter by calling BluetoothAdapter.getDefaultAdapter(). 

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

To start discover, simply call the startDiscovery() from bluetooth adapter. This process is asynchronous so it will return immediately. To catch the discovery process, we can register a BroadcastReceiver with ACTION_FOUND,  ACTION_DISCOVERY_STARTED,  ACTION_DISCOVERY_STARTED. For each device found, the intent will carry extra field  EXTRA_DEVICE containg the BluetoothDevice object.

IntentFilter filter = new IntentFilter();


registerReceiver(mReceiver, filter);

The receiver:

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
	    public void onReceive(Context context, Intent intent) {
	        String action = intent.getAction();

	        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
	        	//discovery starts, we can show progress dialog or perform other tasks
	        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
	        	//discovery finishes, dismis progress dialog
	        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                       //bluetooth device found
	        	BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

	        	showToast("Found device " + device.getName());

And, don’t forget to unregister the receiver on Activity’s onDestroy method:

	public void onDestroy() {


Download the sample APK and source code from github

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather


  1. Ivan says

    How rotation of screen (or other configuration change) affect bluetooth discovery and scanning dialog? Would you save already found devices nad list them again on activity recreation or just start discovery again with empty list (which is not actually nice solution but more something like workaround). Thank you…

    • says

      Hi Ivan,

      I think it is good to save the already found devices. Then after the activity recreated again, save them (from onSavedInstanceState) on the list then start rescanning. We don’t have to use an empty list, just use the saved list and when a new device found, check if it already exists in the list or not. Also it is a good practice to allow user to cancel scanning using progress dialog with a cancel button.

      • Ivan says

        Thanks for answer.. I did it already like that but I mess up something with fragment lifecycle and on discovery finished callback to dismiss dialog.. Sometimes I get crash cause dialog is not there and broadcast is initiating it’s dismission..btw I solved canceling BT discovery by dismissing dialog :D

  2. Dhan says

    thank you very much sir.. this app was everything i wanted to know… thank you thank you…. you save me really ^_^

    more power and god bless… btw can we friends in FB? here’s mine.. (FB Account)

    thanks again

  3. Manish Patel says

    Hi Thanx for your tutorial. It’s perfectly working in my case. Now i want to develop a Bluetooth chat type of app. I successfully developed but in server side code i found one issue. Server want able to connect to my Client using serversocket.accept() method. Do you have any idea to overcome this issue? any help!!!

  4. vasthav says

    This is awesome. I been working on something like this for long time
    but was unable to make it work. This help me a lot. Thank you :)

Leave a Reply

Your email address will not be published. Required fields are marked *