Android dialog for displaying and selecting nearby bluetooth devices. Results are sorted by RSSI level.
Add the JitPack repository to your root Project gradle file at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to the Module gradle file:
dependencies {
...
implementation 'com.github.phearme:bt-scan-selector:1.1.9'
}
Enable databinding in the Module grade file:
android {
...
dataBinding {
enabled = true
}
}
BTScanSelectorBuilder.build(MainActivity.this, new ABTScanSelectorEventsHandler() {
@Override
public void onDeviceSelected(BluetoothDevice device) {
Log.d("DEBUG", String.format("device selected by user: %s\t%s", device.getName(), device.getAddress()));
}
}, "Dialog Title");
Filtering out devices is possible by overriding the onDeviceFound
method. Return true
if you want the device to be included in the result, false
otherwise.
BTScanSelectorBuilder.build(MainActivity.this, new ABTScanSelectorEventsHandler() {
@Override
public boolean onDeviceFound(BluetoothDevice device) {
return device.getName().equals("myDevice") || device.getAddress().equals("AA:BB:CC:DD:EE:FF");
}
@Override
public void onDeviceSelected(BluetoothDevice device) {
Log.d("DEBUG", String.format("device selected by user: %s\t%s", device.getName(), device.getAddress()));
}
});