Host permissions
Donkeh.Hosting.Host exposes the current platform and awaitable
permission requests. The framework supplies desktop, Android and browser
providers, so application code uses one API everywhere.
Platform flags
using Donkeh.Hosting;
if (Host.IsAndroid)
{
// Android-only setup.
}
if (Host.IsDesktop || Host.IsWeb)
{
// Shared responsive path.
}
Console.WriteLine(Host.PlatformName);
| Member | True when |
|---|---|
Host.IsAndroid | Running on Android. |
Host.IsIOS | Running on iOS. |
Host.IsWindows | Running on Windows. |
Host.IsMac | Running on macOS. |
Host.IsLinux | Running on Linux. |
Host.IsWeb | Running in a browser. |
Host.IsBrowser | Alias for IsWeb. |
Host.IsDesktop | Windows, macOS or Linux, excluding the browser. |
Host.IsMobile | Android or iOS. |
Host.PlatformName | A friendly name such as Web or Windows. |
Requesting a permission
Every permission method returns Task<bool> and accepts an
optional CancellationToken.
using Donkeh.Hosting;
if (await Host.Permissions.Camera())
{
// Open the camera.
}
| Method | Capability |
|---|---|
Camera() | Camera capture. |
Microphone() | Audio capture. |
Location() | Current location. |
Notifications() | System notifications. |
Photos() | Photo library / images. |
Storage() | File storage access. |
Contacts() | Contacts. |
Calendar() | Calendar. |
Bluetooth() | Nearby Bluetooth devices. |
Motion() | Motion or activity data. |
Clipboard() | System clipboard. |
A known permission can also be requested through the enum:
Host.Permissions.Request(HostPermission.Camera).
Behaviour
- Granted results are cached for the session.
- Denied results are not cached, so the app can retry after the user changes a setting.
- Concurrent calls for the same permission share one in-flight request.
- Unsupported capabilities return
falseinstead of throwing. - Cancellation is best-effort; a platform prompt may still be visible after the task completes.
Platform providers
| Host | Provider |
|---|---|
| Desktop | Default grants access and lets the device API fail if the OS has blocked it. |
| Android | Requests runtime permissions from the activity and completes from OnRequestPermissionsResult. |
| Browser | Uses getUserMedia, geolocation, Notification, Storage, DeviceMotion and Clipboard APIs. |
| iOS / unsupported | Returns false until a host installs a provider. |
Android manifest
The app can let the framework generate the matching
uses-permission entries. Add the permission tokens to the
project file:
<PropertyGroup>
<DonkehAndroidPermissions>Camera;Microphone;Location;Notifications</DonkehAndroidPermissions>
</PropertyGroup>
Supported tokens are Camera, Microphone,
Location, Notifications, Photos,
Storage, Contacts, Calendar,
Bluetooth and Motion. The framework emits the
entries into the merged Android manifest. You can still use a hand-written
manifest if you prefer.
The framework also adds INTERNET automatically when the app’s
stylesheets contain a remote @import or url(...).
Remote imports (icon fonts, for example) are fetched by the native host at
start-up, and release APKs do not receive INTERNET implicitly
the way debuggable builds do. Set
DonkehAndroidInternet to auto (the default),
true or false to override detection.
Custom providers
A host can replace the permission provider during startup. Implement
IPermissionService and install it before mounting the app:
using Donkeh.Hosting;
public sealed class MyPermissionService : IPermissionService
{
public Task<bool> RequestAsync(
HostPermission permission,
CancellationToken cancellationToken = default)
{
// Ask the platform, then return true or false.
return Task.FromResult(false);
}
}
Host.UsePermissions(new MyPermissionService());
Host.UsePermissions(null) restores the desktop default. Calling
it clears cached grants so a new platform session starts clean.
Host.Permissions call works on desktop, Android and the
browser without platform-specific #if blocks in application
code.