How azhon/appupdate works
Project type and purpose
• This is an Android client library (appupdate) plus a no-op variant (appupdate-no-op) and a demo application (app).
• Purpose: provide an in-app APK update mechanism (dialog, background download, notification, install) that any Android app can integrate via Gradle.
High-level module structure
• app/ → Demo Android application
• appupdate/ → Core AAR library module with full implementation
• appupdate-no-op/ → A no-operation stub library (for Google Play flavor)
• build scripts & configs at root (settings.gradle, maven_publish.sh, Gradle wrappers)
a. Demo App (MainActivity)
• Invokes manager.download()
b. Library Core
• DownloadManager
– Builder pattern to collect parameters and kick off process
– Version check logic (apkVersionCode)
– Decides whether to show dialog or just download
• UI Layer
– UpdateDialogActivity (customizable dialog with progress bar for forced update)
• Service
– DownloadService handles background download on Android 10+ via startForegroundService
• Download Manager Implementation
– BaseHttpDownloadManager (abstract class)
– HttpDownloadManager (uses HttpURLConnection to fetch APK)
• Notification Manager
– NotificationUtil posts progress notifications, requests notification permission on Android 13
• File & APK Utilities
– ApkUtil (delete old APKs, trigger install via FileProvider)
– FileUtil, DensityUtil, LogUtil
c. Android OS
• Notification subsystem (permission, channel, progress bar)
• Background service lifecycle (Service / foreground requirement)
• FileProvider (install intent)
• Activity stack (dialog vs. background restrictions)
Interactions and data flows
1. Demo App → DownloadManager.Builder: set parameters
2. DownloadManager.build() → internal Controller
3. Controller checks remote versionCode vs. current
– If update needed: show UpdateDialogActivity
• User taps “Update” → triggers download
– Else if no version check: proceed straight to download
4. DownloadManager hands off to DownloadService (foreground)
5. DownloadService instantiates HttpDownloadManager
6. HttpDownloadManager streams .apk bytes → writes to externalCacheDir
• Emits progress → NotificationUtil updates notification progress bar
7. On complete → NotificationUtil posts “install” notification / DownloadService calls ApkUtil.install()
8. ApkUtil invokes FileProvider intent → OS package installer UI
Architectural patterns & principles
• Modularization: demo app separated from core update logic
• Builder pattern: DownloadManager.Builder for fluent configuration
• Template method / inheritance: BaseHttpDownloadManager → concrete HttpDownloadManager or custom subclass
• Service for resilience: background download survivable across Activity lifecycle
• Separation of concerns: UI (dialog), network (HttpDownloadManager), file I/O (FileUtil), notifications (NotificationUtil)