feat: send notification when new app update is available (v1.1.7)
Build & Release Android APK / Build & Publish Release APK (push) Waiting to run

This commit is contained in:
Vaishno Singh
2026-11-19 10:24:51 +05:30
parent e1bcfa21f8
commit 256cc6cfc8
5 changed files with 49 additions and 3 deletions
@@ -10,8 +10,16 @@ class AppSettings(private val storage: KeyValueStorage) {
private const val KEY_BIOMETRIC_ENABLED = "key_biometric_enabled"
private const val KEY_BG_MONITOR_ENABLED = "key_bg_monitor_enabled"
private const val KEY_LAST_STATUS_PREFIX = "last_status_"
private const val KEY_LAST_NOTIFIED_VERSION = "key_last_notified_version"
}
var lastNotifiedUpdateVersion: String?
get() = storage.getString(KEY_LAST_NOTIFIED_VERSION, null)
set(value) {
if (value != null) storage.putString(KEY_LAST_NOTIFIED_VERSION, value)
else storage.remove(KEY_LAST_NOTIFIED_VERSION)
}
var isBiometricEnabled: Boolean
get() = storage.getBoolean(KEY_BIOMETRIC_ENABLED, true)
set(value) = storage.putBoolean(KEY_BIOMETRIC_ENABLED, value)
@@ -210,6 +210,11 @@ fun MainScreen(
is UpdateCheckResult.UpdateAvailable -> {
availableUpdate = result.info
showUpdateDialog = true
val newVer = result.info.versionName
if (appSettings.lastNotifiedUpdateVersion != newVer) {
appSettings.lastNotifiedUpdateVersion = newVer
com.expapp.trigger.worker.NotificationHelper.sendUpdateAvailableNotification(context, newVer)
}
if (isManual) {
Toast.makeText(context, "New update available: v${result.info.versionName}!", Toast.LENGTH_SHORT).show()
}
@@ -45,12 +45,16 @@ object NotificationHelper {
id: Int,
title: String,
message: String,
isSuccess: Boolean = true
isSuccess: Boolean = true,
extraAction: String? = null
): Boolean {
createNotificationChannel(context)
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
if (extraAction != null) {
putExtra("action_trigger", extraAction)
}
}
val pendingIntent = PendingIntent.getActivity(
context,
@@ -81,6 +85,17 @@ object NotificationHelper {
}
}
fun sendUpdateAvailableNotification(context: Context, newVersion: String): Boolean {
return sendNotification(
context = context,
id = 8888,
title = "🚀 Update Available: v$newVersion",
message = "A new version (v$newVersion) of Device Trigger is ready to install. Tap to update!",
isSuccess = true,
extraAction = "open_update"
)
}
fun sendTestNotification(context: Context): Boolean {
return sendNotification(
context = context,
@@ -120,6 +120,24 @@ class ServerMonitorWorker(
}
}
// Check for app updates in the background and notify if a new update is found
try {
val updateManager = com.expapp.trigger.update.UpdateManager(appContext)
val currentVersion = com.expapp.trigger.BuildConfig.VERSION_NAME
updateManager.checkForUpdate(currentVersion) { result ->
if (result is com.expapp.trigger.update.UpdateCheckResult.UpdateAvailable) {
val newVer = result.info.versionName
val lastNotified = appSettings.lastNotifiedUpdateVersion
if (lastNotified != newVer) {
appSettings.lastNotifiedUpdateVersion = newVer
NotificationHelper.sendUpdateAvailableNotification(appContext, newVer)
}
}
}
} catch (_: Exception) {
// Ignore background check failure
}
return Result.success()
}
}