🔄 ForceUpdate
Enforce minimum app version with blocking or soft update dialogs
Overview
The ForceUpdate module allows you to enforce minimum app versions for your users. It supports blocking updates (user cannot proceed without updating) and soft recommendations with skip options. Works with Remote Config for dynamic control.
Basic Usage
// In MainActivity.onCreate()
ADict.ForceUpdate.check(activity) {
minVersionCode = 15
storeUrl = "https://play.google.com/store/apps/details?id=com.example"
onUpdateRequired = { currentVersion, minVersion ->
Log.w("Update", "Required: $currentVersion < $minVersion")
}
onUpToDate = {
proceedToMainScreen()
}
}
Auto-Show Dialog
// Automatically shows appropriate dialog
ADict.ForceUpdate.checkAndShowDialog(activity) {
minVersionCode = 15 // Required minimum
recommendedVersionCode = 20 // Soft recommendation
blocking = true // Cannot dismiss required update
showSkipOption = true // Show "Skip this version" for recommended
storeUrl = "https://play.google.com/..."
}
Remote Config Integration
// Check versions from Remote Config
ADict.ForceUpdate.checkFromRemoteConfig(
activity = activity,
minVersionKey = "min_app_version",
recommendedVersionKey = "recommended_app_version",
storeUrlKey = "store_url",
blocking = true,
showDialog = true
) { result ->
when (result) {
is ForceUpdate.CheckResult.UpToDate -> proceedNormally()
is ForceUpdate.CheckResult.UpdateRequired -> { /* Dialog shown */ }
is ForceUpdate.CheckResult.UpdateRecommended -> { /* Dialog shown */ }
is ForceUpdate.CheckResult.Error -> Log.e("Update", result.message)
}
}
// Remote Config keys:
// min_app_version: 15
// recommended_app_version: 20
// store_url: "https://play.google.com/..."
Custom Strings
All dialog strings are configurable. Create a custom Strings instance:
import rip.nerd.adictlibrary.modules.ForceUpdate
// Custom strings for different languages
val germanStrings = ForceUpdate.Strings(
updateRequiredTitle = "Aktualisierung erforderlich",
updateRequiredMessage = "Bitte aktualisieren Sie die App.",
updateRecommendedTitle = "Update verfügbar",
updateRecommendedMessage = "Eine neue Version ist verfügbar.",
updateButton = "Aktualisieren",
laterButton = "Später",
skipButton = "Überspringen"
)
ADict.ForceUpdate.checkAndShowDialog(activity, strings = germanStrings) {
minVersionCode = 15
}
// Or inline for specific case
ADict.ForceUpdate.checkAndShowDialog(
activity = activity,
strings = ForceUpdate.Strings(
updateRequiredTitle = "Critical Security Update",
updateRequiredMessage = "A security vulnerability was found. Please update immediately.",
updateButton = "Update Now"
)
) {
minVersionCode = 20
blocking = true
}
Available String Properties
| Property | Default Value | Description |
|---|---|---|
updateRequiredTitle |
"Update Required" | Title for blocking update dialog |
updateRequiredMessage |
"Your app version is outdated..." | Message for blocking update dialog |
updateRecommendedTitle |
"Update Available" | Title for soft update dialog |
updateRecommendedMessage |
"A new version is available..." | Message for soft update dialog |
updateButton |
"Update" | Update button text |
laterButton |
"Later" | Later button text |
skipButton |
"Skip This Version" | Skip button text |
Check Results
| Result | Description |
|---|---|
UpToDate |
App meets all version requirements |
UpdateRequired |
App is below minimum version (blocking) |
UpdateRecommended |
Newer version available (non-blocking) |
Error |
Error during check (with message) |
Version Name Support
// Use version names instead of codes
ADict.ForceUpdate.check(activity) {
minVersionName = "2.0.0" // Parsed as 20000
recommendedVersionName = "2.1.5" // Parsed as 20105
}
Check Interval
// Only check once per hour
ADict.ForceUpdate.check(activity) {
minVersionCode = 15
checkIntervalMs = 60 * 60 * 1000L // 1 hour
}
Utilities
// Get current app version
val versionCode = ADict.ForceUpdate.getAppVersionCode(context)
val versionName = ADict.ForceUpdate.getAppVersionName(context)
// Reset saved data (skipped versions, etc.)
ADict.ForceUpdate.reset()