bluetooth - Android BluetoothAdapter.CancelDiscovery doesn't cancel discovery -
i have discovery status hooked broadcast receiver. can start scan , let stop after default timeout of 12 seconds, , i'll both discoverystarted , discoveryfinished actions. running code
_bluetoothadapter.canceldiscovery();
does not anything. 12 seconds later, discoveryfinished action after times out. how can force thing stop scanning? slowing down bluetooth connection process.
here broadcast receiver subscription:
filter.addaction(bluetoothdevice.actionfound); filter.addaction(bluetoothdevice.actionbondstatechanged); filter.addaction(bluetoothadapter.actiondiscoverystarted); filter.addaction(bluetoothadapter.actiondiscoveryfinished); context.registerreceiver(_bluetoothdevicereceiver, filter);
and handler:
public override void onreceive(context context, intent intent) { string action = intent.action; if (action == bluetoothdevice.actionfound) { bluetoothdevice newdevice = (bluetoothdevice)intent.getparcelableextra(bluetoothdevice.extradevice); interlocked.compareexchange(ref devicefound, null, null)?.invoke(newdevice); } if (action == bluetoothdevice.actionbondstatechanged) { bluetoothdevice newdevice = (bluetoothdevice)intent.getparcelableextra(bluetoothdevice.extradevice); if (newdevice.bondstate == bond.bonded) { interlocked.compareexchange(ref bondcomplete, null, null)?.invoke(newdevice); } } if (action == bluetoothdevice.actionacldisconnected || action == bluetoothdevice.actionacldisconnectrequested) { interlocked.compareexchange(ref disconnected, null, null)?.invoke(); } if (action == bluetoothadapter.actiondiscoverystarted) { interlocked.compareexchange(ref scanningstatechanged, null, null)?.invoke(true); } if (action == bluetoothadapter.actiondiscoveryfinished) { interlocked.compareexchange(ref scanningstatechanged, null, null)?.invoke(false); } }
Comments
Post a Comment