Created
December 24, 2019 10:50
-
-
Save sidishere/7e502fa7c116cf2a2e93877ebc7a2f8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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