Skip to content

Latest commit

 

History

History
59 lines (53 loc) · 1.67 KB

README.md

File metadata and controls

59 lines (53 loc) · 1.67 KB

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.AlonShahaf:bt-scan-selector:1.2.0'
}

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