Interface INearbyActivity
- Namespace
- Plugin.Maui.NearbyConnectivity
- Assembly
- Plugin.Maui.NearbyConnectivity.dll
One thing this device can run on the radio: advertising or discovery.
public interface INearbyActivity
Remarks
Read Advertiser or Discoverer for the instance. The two run independently: either, both, or neither can be active at a time.
Every member is callable from any thread. Changed is raised on the session's event loop, described on DeviceChanged.
Properties
IsActive
Gets whether the activity is running.
bool IsActive { get; }
Property Value
- bool
true from the start until it stops. A discovery restart driven by DiscoveryRefreshInterval or RefreshAsync(CancellationToken) is internal, so this stays true across it.
LastStop
Gets how the activity last stopped.
NearbyActivityStop? LastStop { get; }
Property Value
- NearbyActivityStop
null while the activity runs and before it first stops. Starting clears it.
Remarks
A Faulted stop is the one worth showing: the platform ended an activity the application did not stop, Error says why, and Availability may still read as available.
Methods
StartAsync(CancellationToken)
Starts the activity.
Task StartAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token to abandon the attempt.
Returns
- Task
A task that completes once the activity has started.
Remarks
Idempotent. A second call while the activity runs completes without doing anything.
Checks Availability first and reports a blocked start as an exception rather than starting something that would silently never work. Permissions are the application's to request, because prompting is a user-interface decision and this type has no user-interface affinity. See NearbyPermission.
Exceptions
- NearbyException
The platform returned an error for the start, or something reported by Availability blocks it.
- OperationCanceledException
cancellationTokenwas canceled.
StopAsync()
Stops the activity. Established connections are unaffected.
Task StopAsync()
Returns
- Task
A task that completes once the activity has stopped.
Remarks
Idempotent: stopping an activity that is not running does nothing. Stopping advertising declines the requests still outstanding and cancels a handshake an accepting consent policy started. Stopping discovery removes the devices that were only visible from Devices; connected devices remain.
- See Also
Events
Changed
event EventHandler? Changed
Event Type
Remarks
Both properties already hold their new values when it is raised. Re-read them in the handler. Two changes in quick succession can be observed as one.