startDiscovery method
Starts device discovery
Implementation
Future<bool> startDiscovery() async {
if (isScanning) {
return false;
}
_updateScanState(BluetoothScanState.starting);
try {
// First get bonded devices
final bondedDevices = await getBondedDevices();
// Clear the found devices list and add bonded devices
_devices.clear();
_devices.addAll(bondedDevices);
// Start discovery
final result = await _channel.invokeMethod('startDiscovery');
if (result == true) {
_updateScanState(BluetoothScanState.scanning);
return true;
} else {
_updateScanState(BluetoothScanState.idle);
return false;
}
} catch (e) {
_updateScanState(BluetoothScanState.idle);
return false;
}
}