Skip to content

Instantly share code, notes, and snippets.

@sidishere
Created December 24, 2019 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidishere/7e502fa7c116cf2a2e93877ebc7a2f8a to your computer and use it in GitHub Desktop.
Save sidishere/7e502fa7c116cf2a2e93877ebc7a2f8a to your computer and use it in GitHub Desktop.
private 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);
// If it's already paired, skip it, because it's been listed already
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
{
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
// When discovery is finished, change the Activity title
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
{
setProgressBarIndeterminateVisibility(false);
setTitle("Select a device to connect");
if (mNewDevicesArrayAdapter.getCount() == 0)
{
String noDevices = "No devices";
mNewDevicesArrayAdapter.add(noDevices);
}
}
}
}
;  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment