Plugin.Maui.NearbyConnectivity
1.0.0-preview.1
dotnet add package Plugin.Maui.NearbyConnectivity --version 1.0.0-preview.1
NuGet\Install-Package Plugin.Maui.NearbyConnectivity -Version 1.0.0-preview.1
<PackageReference Include="Plugin.Maui.NearbyConnectivity" Version="1.0.0-preview.1" />
<PackageVersion Include="Plugin.Maui.NearbyConnectivity" Version="1.0.0-preview.1" />
<PackageReference Include="Plugin.Maui.NearbyConnectivity" />
paket add Plugin.Maui.NearbyConnectivity --version 1.0.0-preview.1
#r "nuget: Plugin.Maui.NearbyConnectivity, 1.0.0-preview.1"
#:package Plugin.Maui.NearbyConnectivity@1.0.0-preview.1
#addin nuget:?package=Plugin.Maui.NearbyConnectivity&version=1.0.0-preview.1&prerelease
#tool nuget:?package=Plugin.Maui.NearbyConnectivity&version=1.0.0-preview.1&prerelease
Plugin.Maui.NearbyConnectivity
Plugin.Maui.NearbyConnectivity provides the ability to discover, connect to, and exchange data with nearby devices that run your .NET MAUI application, without a server or an internet connection.
Features
- Discovery. Advertise to nearby devices, and discover the devices that advertise the same
ServiceId. Read them fromDevices, or handleDeviceChanged. - Connection consent. Answer each inbound connection request with
AcceptAsyncorDeclineAsync, or callSetConsentto set a policy that answers for you. An unanswered request times out. - Bytes, files, and streams. Send byte payloads up to 32 KiB, files with progress reporting, and streams (experimental, opt in with
NEARBY001). Receive payloads from every connection in oneawait foreachloop. Received files are staged in the app's cache directory until you move or dispose them. - Presence. Advertise a display name of up to 63 UTF-8 bytes and up to 57 bytes of app-defined data. Both are broadcast unencrypted to nearby devices before a connection exists.
- Encrypted connections. Every connection is encrypted on both platforms. Each one exposes a six-digit
AuthenticationCodethat users compare out of band to detect a man-in-the-middle. - Bindable types.
NearbyDeviceCollectionimplementsINotifyCollectionChanged, andNearbySessionStateimplementsINotifyPropertyChanged. Both raise their events on the UI thread, so XAML binds to them directly. - Permissions and availability.
NearbyPermissionworks withPermissions.RequestAsync<T>()and covers every Android runtime permission the plugin needs.CheckAvailabilityAsyncreports Bluetooth or Wi-Fi turned off, missing Google Play services, or a missingInfo.plistentry. - Trimming and Native AOT. The library is compatible with both.
- Logging. The plugin logs through
ILoggerwith a stableEventIdfor each message. It registers no logging provider and sends no telemetry.
Supported platforms
| Target | Minimum | Support |
|---|---|---|
net10.0-android |
API 24 | Requires Google Play services. Built on Nearby Connections. |
net10.0-ios |
iOS 26.0 | Built on Multipeer Connectivity. |
net10.0 |
None | Reference target for shared code and unit tests. CheckAvailabilityAsync returns NearbyAvailability.Unsupported, and StartAsync throws NearbyException. |
No cross-platform connections. Android connects only to Android, and iOS only to iOS. On iOS, the plugin stops the session when the app enters the background. On Android, a connection lives as long as the process, so it survives backgrounding only if your app runs a foreground service. See Platform behavior.
Install
dotnet add package Plugin.Maui.NearbyConnectivity
Android needs no manifest changes. iOS needs two Info.plist keys. See Set up Android and iOS.
This package replaces Plugin.Maui.NearbyConnections. The 0.x previews under that name are deprecated and receive no fixes.
Usage
Register the plugin
Register the plugin in MauiProgram.cs. Devices discover each other only when they use the same ServiceId.
builder.AddNearbyConnectivity(options => options.ServiceId = "nearbyminimal");
AddNearbyConnectivity registers INearbyConnectivity as a singleton. Inject it, or use NearbyConnectivity.Default where constructor injection is not available. The same method exists on IServiceCollection for a host without a MauiAppBuilder, such as a unit test.
Request permission and start
Advertising and discovery do not start automatically.
if (await Permissions.RequestAsync<NearbyPermission>() != PermissionStatus.Granted)
{
return;
}
nearbyConnectivity.Advertiser.SetConsent(NearbyConsentPolicy.AcceptAll);
await nearbyConnectivity.Advertiser.StartAsync();
await nearbyConnectivity.Discoverer.StartAsync();
AcceptAll accepts every inbound request without a prompt, so use it only in a demo. To prompt the user instead, see Accept and make connections.
Send a message
Pick a NearbyDevice from nearbyConnectivity.Devices, call ConnectAsync, and send on the returned NearbyConnection.
var connection = await device.ConnectAsync();
await connection.SendAsync("Hello"u8.ToArray());
Receive messages
PayloadsAsync merges the inbound payloads from every connection into one IAsyncEnumerable. The stream is single-consumer, so enumerate it in one place.
await foreach (var (sender, payload) in nearbyConnectivity.PayloadsAsync(cancellationToken))
{
using (payload)
{
if (payload is NearbyBytesPayload bytes)
{
var text = Encoding.UTF8.GetString(bytes.Data.Span);
Console.WriteLine($"{sender.Presence.DisplayName}: {text}");
}
}
}
These snippets follow samples/Minimal, the app from the Get started tutorial.
Documentation
- Get started builds a working two-device app in eight steps.
- How-to guides: Accept and make connections, Send and receive payloads, Show a presence before connecting, Bind to a MAUI page, Test code that uses the plugin, Troubleshooting, and Turn on logging.
- Security and Platform behavior document the plugin's limitations. Read both before you ship.
- API reference and Options and limits
- Samples:
NearbyChatshows consent prompts with a countdown, authentication code checks before the first send, presence avatars, file transfer with cancel and retry, and an Android foreground service that keeps connections open in the background.
Feedback and contributing
Issues and pull requests are welcome. See CONTRIBUTING.md. Ask questions in Discussions. Report bugs and request features with the issue forms.
Report vulnerabilities privately through SECURITY.md. Do not open a public issue.
Licensed under the MIT License.
Acknowledgements
This plugin started from Gerald Versluis's Plugin.Maui.Feature template.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.110)
-
net10.0-android36.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.110)
- Xamarin.GooglePlayServices.Nearby (>= 119.3.0.7)
-
net10.0-ios26.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.110)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.1 | 53 | 10/11/2026 |