Scanning
Scan devices
A device is required to make a transaction , at this point you can scan devices.
You will have to use the SDKDeviceScanService to scan for devices, and select any of the found devices. To create a SDKDeviceScanService, you can use the SDKDeviceScanServiceFactory.create() method to create one.
val readerService = SDKDeviceScanServiceFactory.create()
Then, simply use one of the two scan method (one for using it from an Activity and other from a Fragment) passing the corresponding arguments. To use this, you must first ask for those permissions related to bluetooth.
class MyActivity : AppCompatActivity(), SDKScannerResultListener {
fun startScanning() {
readerService.scan(this, 120000)
}
}
The most important parameter the scan method receives is the SDKScannerResultListener, this listener is used to handle the result the results of the scanning process.
override fun onDeviceListUpdated(list: List<SDKDevice>) {
// TODO: Implement the logic to handle the list of devices found by the scanner
showDevicesToSelectDialog(list)
}
override fun onScanFinish() {
// TODO: Implement the logic to handle the scanning process being stopped
}
override fun onError(type: SDKScannerResultListener.ErrorType, message: String?) {
// TODO: Implement the logic to handle the different errors that may happen when scanning
handleScannerError(type, message)
}