Reputation: 13
I am looking for a way to scan for all bluetooth devices with certain names (lets say "SC_0001", "SC_0002", e.t.c.) and automatically pair them with my phone.
i already created an app that can list all paired devices and let the user select one. but i dont want the user to have to pair all these devices manually (it whould take way too much time).
Upvotes: 0
Views: 2121
Reputation: 2510
You can use getname()
method of the BluetoothDevice class
According to the Documentation of getname()
Get the friendly Bluetooth name of the remote device.
The local adapter will automatically retrieve remote names when performing a device scan, and will cache them. This method just returns the name for this device from the cache.
Then, compare both the strings using str1.equals(str2)
method.
Edit 1
Here is the way, you can get the list of unpaired devices.
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 it's already paired, skip it, because it's been listed already
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
{
// compare device.getName() and your string here, if satisfied, add them to the list-view.
tv.setText(device.getName() + "\n" + device.getAddress());
Here is the link to documentation. BluetoothDevices
Upvotes: 1