I am able to retrieve the paired device names and address, but I don't know how I can retrieve the available bluetooth devices name and address?
   String outV="";
   b1=(Button)findViewById(R.id.button1);
    b2=(Button)findViewById(R.id.button2);
    tv=(TextView)findViewById(R.id.textView1);
    b1.setOnClickListener(new View.OnClickListener() {
        BluetoothAdapter Badap = BluetoothAdapter.getDefaultAdapter();
        @Override
        public void onClick(View arg0) {
            Set<BluetoothDevice> pairedDevices= Badap.getBondedDevices();
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {
                    outV+= device.getName() + " ::" + device.getAddress()+"\n";
                }
                tv.setText(outV);
            }
this is the code for paired device..
In my OnCreate I'm doing
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(MydeviceReceiver, filter);  
Where MydeviceReceiver is
    private final BroadcastReceiver deviceReceiver = 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);
                if( !PairedDeviceNames.contains(device) && !newDevices.contains(device))
                    newDevices.add(device);                
            }
            else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) 
            {
                Log.v(" ","discovery Finished ");
                if(newDevices.size() != 0)
                {                   
                    deviceList.invalidateViews();
                    sectionAdapter.notifyDataSetChanged();
                }
                else
                {
                    Toast.makeText(YourActivity.this, "No New Devices Found", Toast.LENGTH_LONG).show();
                }
            }
        }
    };
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With