Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the devices in the range by using bluetooth?

I am new to android.I want to develop an application to find the devices in the range by using Bluetooth programmatically.If any one has idea please give some sample code to me.

like image 590
kiran Avatar asked Jun 24 '11 05:06

kiran


1 Answers

Find The Devices in the Range by using Bluetooth programmatically.

Yes you can do this using BroadcastReceiver, check out below code, it will help you.

Starting search

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

Finds a device

    if (BluetoothDevice.ACTION_FOUND.equals(action)) 
    {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // Add the name and address to an array adapter to show in a ListView
       mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
    }
  }
};

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
registerReceiver(mReceiver, filter);
like image 132
Deepthi Avatar answered Nov 14 '22 22:11

Deepthi