Bonoscan.Native.Maui.Android 0.31.0

Bonoscan.Native.Maui.Android

Android head of the Bonoscan native MAUI document scanner — a thin wrapper over Google ML Kit Document Scanner (GmsDocumentScanning): the Google-provided full-screen scanner with edge detection, auto-capture, filters, cleanup, multi-page and optional PDF. No custom CV, no model bundled (ML Kit's scanner module is delivered via Google Play services).

Implements IDocumentScanner from Bonoscan.Native.Maui.Abstractions (brought in transitively). Targets net10.0-android.

Setup

1. Reference the package (per-head in a multi-target app)

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
  <PackageReference Include="Bonoscan.Native.Maui.Android" Version="..." />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
  <PackageReference Include="Bonoscan.Native.Maui.iOS" Version="..." />
</ItemGroup>

2. Register the scanner (MauiProgram.cs)

using Microsoft.Extensions.DependencyInjection;

builder.Services.AddBonoscanNativeScanner();   // registers IDocumentScanner as a singleton

3. Force-construct the scanner in MainActivity.OnCreate (required)

The scanner registers an ActivityResult launcher in its constructor, and AndroidX requires that to happen before the activity is RESUMED. Force-resolve the singleton in OnCreate so the launcher is registered at the right moment — without this, the scan Launch throws:

using Bonoscan.Native.Maui;
using Microsoft.Extensions.DependencyInjection;

protected override void OnCreate(Bundle? savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    IPlatformApplication.Current?.Services.GetService<IDocumentScanner>();
}

4. Permissions (Platforms/Android/AndroidManifest.xml)

<uses-permission android:name="android.permission.CAMERA" />
<!-- ML Kit scanner module is delivered via Google Play services on first use -->
<uses-permission android:name="android.permission.INTERNET" />

ScanAsync requests the runtime camera permission for you (via MAUI Essentials) before launching, and returns a failed result with Error = "Camera permission was denied." if the user declines — you don't need to request it yourself.

Note: the ML Kit scanner activity is hosted by Google Play services in its own process and can capture without the host app holding CAMERA. The runtime request is built in to match the declared manifest permission and give a uniform, predictable flow across both heads; if you prefer to let Play services own the prompt entirely, you can drop the CAMERA entry above.

Usage

@inject IDocumentScanner Scanner

var result = await Scanner.ScanAsync(new DocumentScanOptions
{
    MaxPages = 5,
    Mode = ScannerMode.Full,
    ResultFormats = new[] { ScanResultFormat.Jpeg },   // or include ScanResultFormat.Pdf
});

if (result.Success)
{
    foreach (var path in result.ImagePaths) { /* read/preview the JPEG */ }
    if (result.PdfPath is { } pdf) { /* … */ }
}

Android honours all four knobs (SupportedOptions = MaxPages | GalleryImport | ResultFormats | ScannerMode). Output files live in FileSystem.CacheDirectory.

Binding caveat

References the community wrapper Net.Google.MLKit.DocumentScanner 16.1.0 (namespace Net.Google.MLKit.Vision.DocumentScanner). If dotnet restore reports it doesn't support net10.0-android, either target net9.0-android for this head, or switch to Microsoft's MIT binding Xamarin.GooglePlayServices.MLKit.DocumentScanner and adjust the using namespace (the Gms… types are the same). All ML Kit usage is in one file, so swapping the binding is localized.

Licensing

Package code is MIT. ML Kit's scanner ships via Google Play services (no model weights bundled). The Android binding is OSS; Microsoft's alternative binding is MIT.

No packages depend on Bonoscan.Native.Maui.Android.

Version Downloads Last updated
0.31.0 2 06/04/2026