0

I am willing to generate a list which has the list of all the bluetooth enabled devices in the phone's vicinity. The code which I have discovers the devices which are not paired. Is there a way to retrieve the devices which are also paired (if they fall with the vicinity)

The code which discovers all the devices in the vicinity is as follows

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth_connection);

    final TextView tv=(TextView)findViewById(R.id.textView1);
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


    final BroadcastReceiver mReceiver = new BroadcastReceiver() 
    { 
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            String action = intent.getAction(); 
            // When discovery finds a device 
            if (BluetoothDevice.ACTION_FOUND.equals(action)) 
            {
            // Get the BluetoothDevice object from the Intent 
            BluetoothDevice device = intent.getParcelableExtra(
            BluetoothDevice.EXTRA_DEVICE);
            tv.append(device.getName() + "-"+ device.getAddress()+"\n"); 
            }
        }


    };
    String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
    startActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
    registerReceiver(mReceiver, filter); 
    mBluetoothAdapter.startDiscovery();
}

Can any one help me out in adding the code which discovers even the devices which are paired.

Thanks,

Dheeraj R
  • 701
  • 9
  • 17

1 Answers1

0
Set<BluetoothDevice> devices = adapter.getBondedDevices();
    for (BluetoothDevice device : devices) {
      tv.append(device);
    }

I haven't tested this. It's from this tutorial.

Jason Hessley
  • 1,608
  • 10
  • 8
  • When I used the above code, I am still getting the paired devices only and not all the devices...Can you give me further insight to this problem – Dheeraj R Nov 07 '12 at 22:23