Skip to content

feat: add MAUI Android update sample#119

Merged
JusterZhu merged 7 commits into
mainfrom
feat/maui-update-sample
Jun 13, 2026
Merged

feat: add MAUI Android update sample#119
JusterZhu merged 7 commits into
mainfrom
feat/maui-update-sample

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Adds a complete .NET MAUI Android sample demonstrating auto-update integration with GeneralUpdate.Maui.Android, following the same architecture as the existing Avalonia (UI/SemiUrsa) and Avalonia.Android (UI/AndroidUpdate) samples.

Structure

UI/MauiUpdate/
├── nuget.config                # Local package source for development
├── src/MauiUpdate.Android/     # MAUI Android client app
│   ├── MauiProgram.cs          # MAUI DI setup
│   ├── App.xaml(.cs)           # Application entry
│   ├── Models/
│   │   └── UpdatePackageDto.cs # Server response DTO
│   ├── Services/
│   │   └── MauiUpdateHandler.cs # Update bootstrap wrapper
│   ├── ViewModels/
│   │   └── MainViewModel.cs    # MVVM logic with CommunityToolkit.Mvvm
│   └── Views/
│       └── MainPage.xaml(.cs)  # MAUI UI (ProgressBar, status, buttons)
└── server/                     # Minimal API update server
    ├── Server.csproj
    ├── Program.cs               # Version check + APK delivery endpoints
    └── packages/                # versions.json + APK storage

Features

  • Full update lifecycle: Check → Download → Verify SHA256 → Install
  • MVVM pattern using CommunityToolkit.Mvvm (ObservableObject, RelayCommand)
  • Real version detection reads AppInfo.VersionString from installed package
  • Manual JSON parsing avoids AOT/trimming issues
  • Install permission handling — guides user through Android 8+ 'unknown apps' settings
  • Update server with /Upgrade/Verification and /packages endpoints

Verification

  • ✅ APK builds and runs on Huawei Honor X30 (Android 14 / HarmonyOS)
  • ✅ V1.0.0.0 → V2.0.0.0 update flow works end-to-end
  • ✅ Library integration tested with GeneralUpdate.Maui.Android 1.0.1-auth

Co-Authored-By: Claude noreply@anthropic.com

JusterZhu and others added 5 commits June 11, 2026 16:58
- Remove UpgradeMode from VerifyDTO and VerificationResultDTO
- Remove UpgradeMode-based filtering and logging in Program.cs

Co-Authored-By: Claude <noreply@anthropic.com>
- Add UI/AndroidUpdate/ sample project (net10.0-android)
  - Avalonia UI with MVVM pattern (CommunityToolkit.Mvvm)
  - Confirmation dialogs for check and download actions
  - Real-time progress bar with percentage display
  - App version read from PackageManager (not hardcoded)
  - Permission check for Android 8+ unknown app sources
- Reference GeneralUpdate.Avalonia.Android via compiled DLL
  (libs/GeneralUpdate.Avalonia.Android.dll)
- Modify Server/Program.cs to support .apk format downloads
  - Use Format field from versions.json for file extension
  - Search both .zip and .apk in hash lookup
  - Support non-.zip file extensions in hash computation
- Add Android platform entry (Platform=4) to versions.json
- Add BaseUrl and Urls config to Server appsettings.json

Co-Authored-By: Claude <noreply@anthropic.com>
- Rename PackageInfo to UpdatePackageDto to avoid collision with Android SDK type
- Use TaskCreationOptions.RunContinuationsAsynchronously for dialog TCS
- Restore HasUpdate on download failure so retry is possible
- Reset _pendingUpdate only after successful update
- Replace global cleartext flag with targeted network_security_config
- Tighten FileProvider paths to dedicated update/ subfolder only
- Change BaseUrl to localhost (LAN IP was environment-specific)
- Make ServerBaseUrl configurable via ANDROID_UPDATE_SERVER_URL env var

Co-Authored-By: Claude <noreply@anthropic.com>
Adds a complete .NET MAUI Android sample demonstrating auto-update
integration with GeneralUpdate.Maui.Android library.

Includes:
- MauiUpdate.Android client app with MVVM pattern (CommunityToolkit.Mvvm)
- Update server (ASP.NET Minimal API) for version check and APK delivery
- Full update flow: check → download → verify SHA256 → install
- Platform config: AndroidManifest, FileProvider, network security
- Real device version detection via PackageManager
- Support for 'Install unknown apps' permission flow on Android 8+

The sample mirrors the pattern from UI/SemiUrsa (Avalonia) and
UI/AndroidUpdate (Avalonia.Android) samples.

Co-Authored-By: Claude <noreply@anthropic.com>

Signed-off-by: JusterChu <juster.chu@foxmail.com>
Copilot AI review requested due to automatic review settings June 13, 2026 12:33
Adds a .slnx solution file referencing the client and server projects
for easier management in IDEs.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new .NET MAUI Android sample app plus a small companion update server to demonstrate the GeneralUpdate.Maui.Android update flow (check → download → verify → install), and adjusts existing Android/Avalonia sample assets + the main sample server to better support Android APK-style packages.

Changes:

  • Introduces UI/MauiUpdate (MAUI Android client + minimal API server) implementing an end-to-end update workflow.
  • Adds/updates UI/AndroidUpdate (Avalonia Android) UI + handler plumbing and Android resources (manifest/FileProvider/network security).
  • Updates the main sample server to support variable package extensions (e.g., .apk as well as .zip) and adds related configuration.

Reviewed changes

Copilot reviewed 47 out of 51 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
UI/MauiUpdate/src/MauiUpdate.Android/Views/MainPage.xaml.cs MAUI page code-behind wiring DI-provided ViewModel.
UI/MauiUpdate/src/MauiUpdate.Android/Views/MainPage.xaml MAUI UI layout for version/status/progress/actions.
UI/MauiUpdate/src/MauiUpdate.Android/ViewModels/MainViewModel.cs MVVM logic for verification request + download/install workflow.
UI/MauiUpdate/src/MauiUpdate.Android/Services/MauiUpdateHandler.cs Wrapper around GeneralUpdate.Maui.Android bootstrap + events/options mapping.
UI/MauiUpdate/src/MauiUpdate.Android/Resources/Styles/Styles.xaml Shared MAUI styles (Page/Label/Button).
UI/MauiUpdate/src/MauiUpdate.Android/Resources/Styles/Colors.xaml Shared MAUI color resources.
UI/MauiUpdate/src/MauiUpdate.Android/Resources/Splash/splash.svg MAUI splash asset.
UI/MauiUpdate/src/MauiUpdate.Android/Resources/AppIcon/appicon.svg MAUI app icon asset.
UI/MauiUpdate/src/MauiUpdate.Android/Platforms/Android/Resources/xml/network_security_config.xml Android network security config for dev hosts/cleartext.
UI/MauiUpdate/src/MauiUpdate.Android/Platforms/Android/Resources/xml/file_paths.xml FileProvider paths for update artifacts.
UI/MauiUpdate/src/MauiUpdate.Android/Platforms/Android/MainApplication.cs MAUI Android Application entry.
UI/MauiUpdate/src/MauiUpdate.Android/Platforms/Android/MainActivity.cs MAUI Android Activity entry.
UI/MauiUpdate/src/MauiUpdate.Android/Platforms/Android/AndroidManifest.xml Android manifest (permissions, network security config, FileProvider).
UI/MauiUpdate/src/MauiUpdate.Android/Models/UpdatePackageDto.cs DTO for server response + auth fields for downloads.
UI/MauiUpdate/src/MauiUpdate.Android/MauiUpdate.Android.csproj MAUI Android project definition + package references/resources.
UI/MauiUpdate/src/MauiUpdate.Android/MauiProgram.cs MAUI DI registrations (HttpClient, handler, VM, page).
UI/MauiUpdate/src/MauiUpdate.Android/App.xaml.cs MAUI Application + window creation.
UI/MauiUpdate/src/MauiUpdate.Android/App.xaml App resource dictionary merges (colors/styles).
UI/MauiUpdate/server/Server.csproj Minimal API server project for the MAUI sample.
UI/MauiUpdate/server/Program.cs Minimal API endpoints for verification/report and serving APKs.
UI/MauiUpdate/nuget.config Adds local NuGet feed configuration for the MAUI sample.
UI/AndroidUpdate/src/AndroidUpdate.Android/Views/MainView.axaml.cs Avalonia UserControl code-behind initialization.
UI/AndroidUpdate/src/AndroidUpdate.Android/Views/MainView.axaml Avalonia UI for checking/downloading/installing updates + dialog overlay.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/ViewModelBase.cs Base VM type (ObservableObject).
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/UpdatePackageDto.cs Update package record used by Avalonia Android sample.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/MainViewViewModel.cs Avalonia Android sample MVVM workflow and dialog orchestration.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewModels/IAndroidUpdateHandler.cs Abstraction for platform update handler used by the VM.
UI/AndroidUpdate/src/AndroidUpdate.Android/ViewLocator.cs Avalonia view locator for VM→View mapping.
UI/AndroidUpdate/src/AndroidUpdate.Android/Services/AndroidUpdateHandler.cs GeneralUpdate.Avalonia.Android integration for download/verify/install.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/xml/network_security_config.xml Android network security config for Avalonia Android sample.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/xml/file_paths.xml FileProvider paths for the Avalonia Android sample.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values/styles.xml Android styles for splash/theme.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values/colors.xml Android colors for splash background (light).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values-v31/styles.xml Android 12+ splash screen styles.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/values-night/colors.xml Android colors for splash background (dark).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable/splash_screen.xml Drawable splash screen composition.
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable-v31/avalonia_anim.xml Android 12+ animated vector splash (light).
UI/AndroidUpdate/src/AndroidUpdate.Android/Resources/drawable-night-v31/avalonia_anim.xml Android 12+ animated vector splash (dark).
UI/AndroidUpdate/src/AndroidUpdate.Android/Properties/AndroidManifest.xml Avalonia Android manifest (permissions, FileProvider, net sec config).
UI/AndroidUpdate/src/AndroidUpdate.Android/MainActivity.cs Avalonia Android activity entry.
UI/AndroidUpdate/src/AndroidUpdate.Android/App.axaml.cs Avalonia app startup + DI-ish wiring for handler factory.
UI/AndroidUpdate/src/AndroidUpdate.Android/App.axaml Avalonia app styles + data templates.
UI/AndroidUpdate/src/AndroidUpdate.Android/AndroidUpdate.Android.csproj Avalonia Android project definition + references/resources.
UI/AndroidUpdate/src/AndroidUpdate.Android/AndroidApp.cs Avalonia Android Application bootstrapping + version detection + handler factory.
UI/AndroidUpdate/AndroidUpdate.slnx Solution file for the AndroidUpdate sample.
src/Server/wwwroot/packages/versions.json Adds/adjusts package entries (incl. APK-style entry) and formatting.
src/Server/Program.cs Extends download handling to support non-.zip formats via Format.
src/Server/appsettings.json Adds Urls/BaseUrl configuration keys for server binding + link generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +7
<packageSources>
<clear />
<add key="local-packages" value="C:\github code\GeneralUpdate-Samples\UI\local-packages" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Comment on lines +24 to +26
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
Comment thread UI/MauiUpdate/src/MauiUpdate.Android/ViewModels/MainViewModel.cs Outdated
Comment thread UI/MauiUpdate/src/MauiUpdate.Android/ViewModels/MainViewModel.cs Outdated
Comment on lines +118 to +120
var latest = packages[0];
latest.DownloadUrl = $"{_serverUrl}/packages/{latest.PacketName}.apk";

Comment on lines +189 to +191
Format = _pendingUpdate.Format,
Size = _pendingUpdate.Size,
DownloadUrl = $"{_serverUrl}/packages/{_pendingUpdate.PacketName}.apk"
Comment on lines +9 to +13
<!-- Also trust user-installed CAs for debugging -->
<trust-anchors>
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
Comment thread UI/MauiUpdate/server/Program.cs Outdated
Comment on lines +20 to +34
app.MapGet("/packages/{filename}", async (string filename, HttpContext context) =>
{
// Sanitize filename to prevent path traversal
var sanitized = Path.GetFileName(filename);
var filePath = Path.Combine(packagesDir, sanitized);
if (!File.Exists(filePath))
{
return Results.NotFound(new { error = "Package not found.", filename = sanitized });
}

var fileInfo = new FileInfo(filePath);
context.Response.Headers.Append("Content-Disposition", $"attachment; filename=\"{sanitized}\"");
context.Response.Headers.Append("Accept-Ranges", "bytes");
return Results.File(filePath, "application/vnd.android.package-archive", sanitized);
});
Comment on lines +3 to +6
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.50.204</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
- Fix nuget.config: use relative path for local feed, keep nuget.org
- Fix .csproj: use explicit MAUI version instead of unset
- Fix network_security_config: remove hardcoded LAN IP, remove user CAs
- Fix MainViewModel: use generic localhost default, use Format extension
- Fix server endpoint: enable range processing, remove unused variable

Co-Authored-By: Claude <noreply@anthropic.com>
@JusterZhu JusterZhu merged commit 53efc31 into main Jun 13, 2026
2 checks passed
@JusterZhu JusterZhu deleted the feat/maui-update-sample branch June 13, 2026 12:48
@JusterZhu JusterZhu restored the feat/maui-update-sample branch June 13, 2026 16:21
@JusterZhu JusterZhu deleted the feat/maui-update-sample branch June 13, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants