Plugin.Maui.DeviceSession
1.0.0
See the version list below for details.
dotnet add package Plugin.Maui.DeviceSession --version 1.0.0
NuGet\Install-Package Plugin.Maui.DeviceSession -Version 1.0.0
<PackageReference Include="Plugin.Maui.DeviceSession" Version="1.0.0" />
<PackageVersion Include="Plugin.Maui.DeviceSession" Version="1.0.0" />
<PackageReference Include="Plugin.Maui.DeviceSession" />
paket add Plugin.Maui.DeviceSession --version 1.0.0
#r "nuget: Plugin.Maui.DeviceSession, 1.0.0"
#:package Plugin.Maui.DeviceSession@1.0.0
#addin nuget:?package=Plugin.Maui.DeviceSession&version=1.0.0
#tool nuget:?package=Plugin.Maui.DeviceSession&version=1.0.0
Plugin.Maui.DeviceSession
A .NET MAUI plugin for Android and iOS that gives you one API for:
- Device identity (
ANDROID_ID/identifierForVendor) - App installation identity (survives updates, resets on uninstall or data clear)
- Analytics-style sessions (rotate after 30 minutes in the background by default)
Install
Package: https://www.nuget.org/packages/Plugin.Maui.DeviceSession
dotnet add package Plugin.Maui.DeviceSession
Or reference the project:
<ProjectReference Include="..\src\Plugin.Maui.DeviceSession\Plugin.Maui.DeviceSession.csproj" />
Register the plugin
builder
.UseMauiApp<App>()
.UseDeviceSession(options =>
{
options.EnableLogging = true;
options.SessionTimeout = TimeSpan.FromMinutes(30);
options.StartSessionOnInitialize = true;
options.ResumeSessionAcrossProcessRestarts = true;
});
Resolve IDeviceSession from dependency injection, or use DeviceSession.Current.
UseDeviceSession hooks Android OnResume/OnPause and iOS OnActivated/DidEnterBackground so sessions rotate automatically.
Read identity and session
var session = DeviceSession.Current;
var snapshot = session.Snapshot;
var deviceId = snapshot.Identity.DeviceId;
var installationId = snapshot.Installation.InstallationId;
var sessionId = snapshot.Session?.SessionId;
if (snapshot.Installation.IsFirstLaunch)
{
// First run after install or data clear.
}
if (snapshot.Installation.IsUpdated)
{
// First run after an app version change.
}
Manage sessions
session.SessionStarted += (_, e) => { /* persist e.Session.SessionId */ };
session.SessionEnded += (_, e) => { /* e.Reason is Manual, Timeout, or Reset */ };
session.StartSession();
session.EndSession();
session.NotifyForeground();
session.NotifyBackground();
session.ResetInstallation();
ResetInstallation clears persisted install/session state and creates a new installation id. The native device id is unchanged.
What each id means
| Id | Lifetime | Android | iOS |
|---|---|---|---|
DeviceId |
Device / vendor scoped | Settings.Secure.ANDROID_ID |
UIDevice.IdentifierForVendor |
InstallationId |
This app install | GUID in Preferences |
GUID in Preferences |
SessionId |
Until background timeout (default 30 min) | Same | Same |
Android ANDROID_ID is scoped to your app signing key (Android 8+) and changes after factory reset or a signing-key change.
iOS identifierForVendor changes if the user uninstalls every app from the same vendor.
InstallationId is the value to use when you need “this install of this app”. It survives updates and is cleared when the app is uninstalled or its data is wiped.
Host app setup
Android
No extra permissions or manifest entries are required.
iOS
The plugin stores install and session state in Preferences (User Defaults). Add the User Defaults reason to the iOS privacy manifest if you have not already:
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
Platform notes
| Android | iOS | net10.0 |
|
|---|---|---|---|
| Device id | ANDROID_ID |
identifierForVendor |
Persisted fallback GUID |
| Installation / sessions | Yes | Yes | Yes (for shared code and tests) |
These identifiers are not secrets. Treat them as analytics/support identifiers and disclose them in your privacy policy if you send them off-device.
Sample
samples/DeviceSession.Sample shows device identity, installation flags, the current session, and reset.
dotnet build src/Plugin.Maui.DeviceSession/Plugin.Maui.DeviceSession.csproj
dotnet pack src/Plugin.Maui.DeviceSession/Plugin.Maui.DeviceSession.csproj -c Release
dotnet test tests/Plugin.Maui.DeviceSession.Tests/Plugin.Maui.DeviceSession.Tests.csproj
dotnet build samples/DeviceSession.Sample/DeviceSession.Sample.csproj -f net10.0-android
Pack
dotnet pack src/Plugin.Maui.DeviceSession/Plugin.Maui.DeviceSession.csproj -c Release
Packages are written to artifacts/.
| 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.Maui.Controls (>= 10.0.20)
-
net10.0-android36.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-ios26.0
- Microsoft.Maui.Controls (>= 10.0.20)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Plugin.Maui.DeviceSession:
| Package | Downloads |
|---|---|
|
Plugin.Maui.Observability
Umbrella telemetry pipeline for .NET MAUI on iOS and Android. Unifies AppHealth, NetworkMonitor, ApiResilience, BackgroundTasks, OfflineSync, SmartUpload, and DeviceSession into one signal stream, and exports to OpenTelemetry, Application Insights, Sentry, Datadog, Console, or a custom HTTP endpoint. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release: native device IDs, installation identity, first-launch/update detection, and timeout-based sessions for Android and iOS.