Getting The Address And Names Of All Available Bluetooth Devices In Android
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)fi
Solution 1:
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
privatefinalBroadcastReceiverdeviceReceiver=newBroadcastReceiver()
{
@OverridepublicvoidonReceive(Context context, Intent intent)
{
Stringaction= intent.getAction();
// When discovery finds a deviceif (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the IntentBluetoothDevicedevice= intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if( !PairedDeviceNames.contains(device) && !newDevices.contains(device))
newDevices.add(device);
}
elseif (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();
}
}
}
};
Post a Comment for "Getting The Address And Names Of All Available Bluetooth Devices In Android"