Repository navigation
Conversation
Device.CreateBondAsync calls BluetoothDevice.createBond and completes when the adapter reports the device Bonded (true) or back to NotBonded (false). A device that is already bonded returns true at once, and one that is already bonding is waited on rather than asked again. The wait subscribes before starting so a fast outcome is not missed, and only the success state is re-checked afterwards, because straight after createBond Android can still report NotBonded. Device.RemoveBondAsync calls the hidden BluetoothDevice.removeBond by reflection and waits for NotBonded. It is best effort: any refusal, including the method being blocked as a non-SDK interface, is returned as false rather than thrown, and the documentation says so. Both return false on Apple platforms, Windows and stand-in devices, and throw PlatformNotSupportedException on the platform-neutral targets as other native members do. Cancellation stops the wait but not bonding the system has already started. Fixes #35
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #35.
Stacked on #39 (
feature/bond-state, issue #34). This PR merges after #39; GitHub retargets it todevelopmentonce #39 is merged. The diff here shows only the #35 change.Public API (additive only)
Task<bool> Device.CreateBondAsync(CancellationToken cancellationToken = default)Task<bool> Device.RemoveBondAsync(CancellationToken cancellationToken = default)Android
CreateBondAsynccallsBluetoothDevice.createBond(), which shows the system pairing prompt where the peripheral asks for one. It completestruewhen the adapter reportsBonded, andfalsewhen it reportsNotBonded(bonding failed or was refused) or whencreateBondrefuses to start. An already-bonded device returnstrueimmediately. A device alreadyBondingis waited on instead of being asked again.RemoveBondAsynccalls the hiddenBluetoothDevice.removeBond()by reflection and completestruewhen the device reachesNotBonded. Best effort, and documented as such: newer Android versions restrict it, and every refusal (method missing, non-SDK interface blocked, permission denied) is returned asfalse, never thrown. A device that is not bonded returnstrue.Adapter.DeviceBondStateChangedfrom Expose a device's bond state and raise an event when it changes #39, subscribing before starting. Only the success state is re-checked after starting, because Android can still reportNotBondedfor a moment straight aftercreateBond.OperationCanceledException). It does not abort bonding the system has already started. Disposing the device cancels the wait, through the existing combined token.BLUETOOTH_CONNECT,CreateBondAsyncthrows the platform'sSecurityException, which is documented.Other platforms
false, documented. CoreBluetooth offers no bond API. Windows has pairing APIs, but supporting them was outside this issue.false.net10.0/netstandard2.0:PlatformNotSupportedException, like every other native member there.README / release notes
The README Bonding section gains a paragraph and an example on requesting and removing a bond, with the best-effort caveat.
PackageReleaseNotesextends the "Unreleased" paragraph from #39.Verification