Skip to content

Android dialog for displaying and selecting nearby bluetooth devices

License

Notifications You must be signed in to change notification settings

r-cohen/bt-scan-selector

Repository files navigation

bt-scan-selector

Android dialog for displaying and selecting nearby bluetooth devices. Results are sorted by RSSI level.

Installation

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
    }
}

Usage

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");

Filter out devices

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()));
	}
});

About

Android dialog for displaying and selecting nearby bluetooth devices

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages