Introducing a new way to review your PRs.

Read the announcement

capcom6 / android-sms-gateway

The SMS Gateway for Android™ app enables sending and receiving SMS messages through an API that can be accessed directly on the device or via a cloud server when direct device access is not possible.

View on GitHub

20 documents · Updated Nov 20, 2026

docs / notifications

Notifications and foreground services

Notifications give the operator visible signals when the app works in the background. They show that server, real-time, ping, send, and webhook work is active. They also alert the operator when settings change through the API or when incoming SMS webhooks need review.

Notification model

The notification service is the shared boundary for Android notifications. It creates one app channel, chooses a small icon for each activity type, and gives each notification a path back into the app. Callers provide the user-facing message and a stable activity ID. The shared map also gives inbox work its own notification identity and icon so it can remain separate from the other activity signals.

Notification channel

Android 8 and later receive all app notifications through the sms-gateway channel. The channel uses low importance, so it supports status visibility without treating routine gateway work as an urgent alert. Android owns the channel behavior after creation, which means a later app change cannot silently raise or lower its importance for an existing user.

The cloud server settings expose the notification channel choice as Auto or SSE Only. This choice controls how the cloud gateway receives server events. It does not create a second Android notification channel.

References: app/…/NotificationsService.kt• L46-56 app/…/GatewaySettings.kt• L11-14 app/…/cloud_server_preferences.xml• L15-22 app/…/arrays.xml• L34-41

Notification destinations

Most notifications open the app’s normal launch destination when the operator taps them. The incoming-SMS-webhook notice is different: it opens the Settings tab so the operator can review the registered webhook setup.

The notification ID is part of the user-facing contract. A repeated signal with the same ID updates the existing Android notification instead of creating an unrelated item in the notification shade.

References: app/…/NotificationsService.kt• L20-44 app/…/NotificationsService.kt• L59-97

Foreground visibility

Foreground services and foreground workers use notifications to tell Android and the operator that work must remain visible while the app is not open. The service starts with a status message and removes its foreground state when it stops.

Server visibility

The local server shows SMSGate as running on its configured port. The real-time cloud path shows that it is listening to server events. These signals represent two different active connections: the local API server and the cloud event stream.

The real-time path keeps its connection active with wake and Wi-Fi locks, then pulls pending messages when it connects. Its notification therefore signals both an active foreground service and the path that receives cloud events.

References: app/…/WebService.kt• L220-254 app/…/SSEForegroundService.kt• L83-105 app/…/AndroidManifest.xml• L32-41 app/…/AndroidManifest.xml• L77-84

Ping visibility

The ping service shows Ping service is active while it performs health checks at the configured interval. Each check emits a ping event that can prompt the cloud gateway to pull pending work.

The ping service and the server services use the same notification channel, but each has its own notification ID and status message. Stopping the ping service releases its device resources and removes its foreground notification.

References: app/…/PingForegroundService.kt• L49-85 app/…/PingForegroundService.kt• L92-101 app/…/NotificationsService.kt• L86-97

Work visibility

Message sending and webhook processing run as foreground work when Android requires visible background execution. The message worker reports Sending messages…. Webhook work reports either Sending webhook… or Processing webhook queue….

These messages describe active work rather than its final result. The durable outcome remains in the message or webhook state and in the operational log. See Operational logs and retention for the diagnostic record.

References: app/…/SendMessagesWorker.kt• L30-57 app/…/SendMessagesWorker.kt• L60-75 app/…/SendWebhookWorker.kt• L167-181 app/…/WebhookQueueProcessorWorker.kt• L433-442

The main notification flow connects a background event or task to a visible Android signal.

flowchart LR
    A[Server event or scheduled work] --> B[Gateway, message, or webhook service]
    B --> C[Notifications service]
    C --> D[Android notification channel]
    D --> E[Operator notification shade]
    E --> F[App or Settings tab]

Push handling

Push handling lets the cloud gateway wake the app without keeping a cloud event stream open. Firebase Cloud Messaging delivers an event name and optional data. The push service converts that input into the app’s shared event path, where gateway receivers start the related work.

Push registration

When the cloud gateway starts, it registers for push delivery. Firebase token changes are sent to the registration worker, which updates the device registration on the server. Registration failures are retried by background work and are recorded in operational logs.

With SSE Only, the app skips Firebase token registration. It registers the device without a push token, then the gateway event receiver starts the real-time SSE service after registration. With Auto, the app uses Firebase push registration and does not need that SSE fallback for normal event delivery.

References: app/…/PushService.kt• L23-25 app/…/PushService.kt• L54-100 app/…/GatewayService.kt• L44-54 app/…/EventsReceiver.kt• L87-96 app/…/RegistrationWorker.kt• L28-53

Push event routing

The push payload carries an event name and optional data. The push service maps it to a shared external event. The event router then turns it into an internal event such as message enqueue, settings update, webhook update, message export, or message cancellation.

The same internal event path serves push and SSE delivery. This keeps delivery choice separate from the work that follows it. A bad event name or a processing error is logged as a push failure instead of being shown as a user notification.

References: app/…/PushService.kt• L27-51 app/…/EventsRouter.kt• L21-55 app/…/ExternalEventType.kt• L5-20 app/…/EventsReceiver.kt• L28-85

Activity signals

Short-lived notifications mark important changes that do not need a foreground service. They give the operator a signal outside the open activity while the related feature keeps its full state in its own service, worker, or log path.

Webhook signals

When a new sms:received webhook is registered, the app sends a high-priority notification that can open Settings. A periodic review also reminds the operator when incoming-SMS webhooks exist. The review uses a count so the operator can distinguish an empty setup from one with several registered hooks.

Webhook send and queue-processing work use foreground status notifications instead. The short-lived registration and review notices therefore answer “what needs attention?”, while the foreground notices answer “what is running now?”.

References: app/…/WebHooksService.kt• L98-111 app/…/WebHooksService.kt• L213-220 app/…/ReviewWebhooksWorker.kt• L23-40 app/…/NotificationsService.kt• L31-44

Settings signals

When an API update changes at least one setting, the app sends a high-priority notice that says the app must restart to apply the change. An empty update or an update with no changed values sends nothing.

This signal is important because API settings can change while a running service still holds its earlier state. The notice tells the operator that the change was accepted but is not yet active.

References: app/…/SettingsService.kt• L39-63 app/…/strings.xml• L99-100 app/…/HomeFragment.kt• L399-409

Activity signal map

The shared notification service maps each major background activity to one stable signal:

ActivityUser-facing signalNotification behavior
Local serverGateway is running on its portForeground service status
Real-time cloud eventsListening to server eventsForeground service status
Ping checksPing service is activeForeground service status
Message sendingSending messages…Foreground worker status
Webhook deliverySending webhook… or Processing webhook queue…Foreground worker status
New incoming-SMS webhookNew SMS received webhooks registeredHigh-priority alert that opens Settings
API settings changeSettings changed via API; restart requiredHigh-priority alert that opens the app

References: app/…/NotificationsService.kt• L20-38 app/…/WebService.kt• L230-240 app/…/SSEForegroundService.kt• L94-101 app/…/PingForegroundService.kt• L76-84 app/…/SendMessagesWorker.kt• L66-75 app/…/SendWebhookWorker.kt• L173-181 app/…/SettingsService.kt• L54-63

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep each notification ID aligned with its icon, status text, foreground-work owner, and tap destination. A reused ID can replace a different signal.
  • Keep the Auto and SSE Only setting values aligned across the preference list, stored gateway setting, push registration path, and SSE fallback.
  • Keep all foreground services and foreground workers on a notification channel that exists before they start. Android can reject background work when its required foreground notification is missing.
  • Keep push event names aligned with ExternalEventType and with the event receivers that start message, webhook, settings, or export work.
  • Keep high-priority alert behavior separate from low-importance foreground status behavior. Raising one signal must not change the user experience of all gateway status notices.
  • Keep notification text and tap destinations aligned with the operator action that follows the signal. Settings-change alerts must continue to explain the restart requirement.

Important failure modes

TriggerConsequenceGuard
The Android notification channel is disabled or has low user-visible importanceForeground status or short-lived alerts may not be visible or may not interrupt the operatorCheck the app channel settings when background work appears inactive; channel importance is controlled by Android after creation
A foreground service or worker starts without a valid notificationAndroid can stop or reject the background workCreate the shared notification before calling the foreground start path
The notification channel choice is SSE Only but the real-time service cannot connectPush registration is skipped and server events may not reach the deviceCheck SSE service state and operational logs; use Auto when push delivery is required
A push payload has an unknown event name or processing errorThe event is not routed to gateway workInspect the push error entry in operational logs and keep payload names aligned with ExternalEventType
A notification ID is changed in only one caller or destination mapAndroid may show the wrong icon, replace an unrelated signal, or open the wrong screenTreat IDs as shared contracts in NotificationsService and its callers
Settings change through the API while a service is runningThe operator sees an accepted change but the active service can continue with old state until restartFollow the restart notice before relying on the new setting

Key files

FileWhy to read it
app/…/NotificationsService.ktShared notification channel, IDs, icons, priority rules, and tap destinations
app/…/GatewaySettings.ktCloud notification-channel choices and their stored values
app/…/cloud_server_preferences.xmlOperator-facing choice between automatic push delivery and SSE-only delivery
app/…/SSEForegroundService.ktReal-time server event visibility and connection lifecycle
app/…/WebService.ktLocal server foreground status and port signal
app/…/PingForegroundService.ktPing service status and foreground lifecycle
app/…/PushService.ktFirebase token registration and push-to-event conversion
app/…/EventsRouter.ktShared routing from external events to gateway work
app/…/SendMessagesWorker.ktForeground visibility for outgoing message work
app/…/WebHooksService.ktUser alerts for new incoming-SMS webhook registration
app/…/ReviewWebhooksWorker.ktPeriodic reminder for registered incoming-SMS webhooks
app/…/SettingsService.ktNotification raised after API settings changes
app/…/AndroidManifest.xmlDeclared push receiver and foreground-service types

Parent: User interface and operations
Related: Operational logs and retention