An Android application that automatically forwards incoming SMS messages to Telegram. Features spam detection, reliable background service with auto-restart, and a modern Material 3 UI.
- Telegram Forwarding: Automatically forward SMS messages to a Telegram chat via bot API
- Spam Detection: Rule-based spam filtering with keywords, patterns, blacklists, and whitelists
- Reliable Background Service: Foreground service with wake lock and auto-restart on termination
- Boot Persistence: Automatically starts on device boot
- Health Monitoring: Periodic health checks with status notifications
- Message History: Local database storage of all received messages
- Notification System: Configurable notifications for forwarding success, errors, and spam detection
- Modern UI: Material 3 design with Jetpack Compose
- Dark Mode: System, light, and dark theme support
| Home Screen | Settings | History | Spam Rules |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Note: Add screenshots to a
screenshots/folder in the project root.
flowchart TD
subgraph Android_System [Android System]
SMS[Incoming SMS]
Boot[Boot Completed]
end
subgraph Receivers [Broadcast Receivers]
SmsReceiver[SmsReceiver]
BootReceiver[BootReceiver]
RestartReceiver[RestartReceiver]
end
subgraph Service [Background Service]
SmsForwarderService[SmsForwarderService]
ForwarderManager[ForwarderManager]
HealthChecker[HealthChecker]
end
subgraph Domain [Domain Layer]
SpamDetector[SpamDetector]
TelegramForwarder[TelegramBotForwarder]
end
subgraph Data [Data Layer]
Repository[SmsRepository]
Database[(Room Database)]
Preferences[(DataStore)]
end
subgraph External [External Services]
TelegramAPI[Telegram Bot API]
end
SMS --> SmsReceiver
Boot --> BootReceiver
BootReceiver --> SmsForwarderService
RestartReceiver --> SmsForwarderService
SmsReceiver --> ForwarderManager
ForwarderManager --> SpamDetector
SpamDetector --> Repository
ForwarderManager --> TelegramForwarder
TelegramForwarder --> TelegramAPI
ForwarderManager --> Repository
Repository --> Database
SmsForwarderService --> HealthChecker
HealthChecker --> Preferences
- SMS Received: Android broadcasts
SMS_RECEIVEDintent - SmsReceiver: Captures the broadcast, extracts message data
- ForwarderManager: Orchestrates the forwarding pipeline
- SpamDetector: Checks message against spam rules
- TelegramBotForwarder: Sends message to Telegram via Bot API
- SmsRepository: Saves message history to Room database
app/src/main/java/com/example/sms_fwd_1/
├── data/
│ ├── local/
│ │ ├── entity/ # Room entities (LogEntity, SmsHistoryEntity, SpamRuleEntity)
│ │ ├── AppDatabase.kt # Room database definition
│ │ └── *Dao.kt # Data Access Objects
│ ├── preferences/
│ │ └── AppPreferences.kt # DataStore preferences manager
│ └── repository/
│ └── SmsRepository.kt # Data repository
├── domain/
│ ├── forwarder/
│ │ ├── TelegramBotForwarder.kt # Telegram implementation
│ │ ├── EmailForwarder.kt # Email implementation (placeholder)
│ │ ├── WebhookForwarder.kt # Webhook implementation (placeholder)
│ │ └── SmsForwarder.kt # SMS forwarding (placeholder)
│ ├── model/
│ │ ├── SmsMessage.kt # SMS domain model
│ │ └── ForwardResult.kt # Forwarding result sealed class
│ └── spam/
│ ├── SpamDetector.kt # Spam detection logic
│ └── SpamRule.kt # Spam rule definitions
├── receiver/
│ ├── SmsReceiver.kt # SMS broadcast receiver
│ ├── BootReceiver.kt # Boot completed receiver
│ └── RestartReceiver.kt # Service restart receiver
├── service/
│ ├── SmsForwarderService.kt # Main foreground service
│ ├── ForwarderManager.kt # Forwarding orchestrator
│ ├── NotificationService.kt # Notification management
│ ├── HealthChecker.kt # Service health monitoring
│ └── AppLogger.kt # Logging utility
├── ui/
│ ├── components/ # Reusable Compose components
│ ├── navigation/ # Navigation setup
│ ├── screens/ # Screen composables and ViewModels
│ └── theme/ # Material 3 theme
├── worker/
│ └── HealthCheckWorker.kt # WorkManager health check
├── MainActivity.kt # Main activity
└── SmsForwarderApp.kt # Application class
- Android device running Android 8.0 (API 26) or higher
- Telegram account with a bot created via BotFather
- Download the APK from Releases
- Enable "Install from unknown sources" in device settings
- Install the APK
- Grant required permissions when prompted
# Clone the repository
git clone https://github.com/yourusername/sms-forwarder.git
cd sms-forwarder
# Build debug APK
./gradlew assembleDebug
# Build release APK
./gradlew assembleRelease- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow the prompts to set bot name and username
- Copy the Bot Token (format:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
Option A: Using @userinfobot (Recommended)
- Search for @userinfobot on Telegram
- Start the bot - it will reply with your Chat ID
Option B: Using @getidsbot
- Search for @getidsbot on Telegram
- Start the bot or forward a message to get the Chat ID
Option C: For Groups
- Add your bot to the group
- Send a message in the group
- Visit:
https://api.telegram.org/bot<BOT_TOKEN>/getUpdates - Find the
chat.idin the response (negative number for groups)
IMPORTANT: You must complete this step before the bot can send you messages!
- Open Telegram and search for @smsfwd1bot
- Tap Start or send any message to the bot
- The bot will confirm it can now send you messages
Note: Telegram bots cannot initiate conversations due to privacy restrictions. You must message the bot first to allow it to send you forwarded SMS messages.
- Open SMS Forwarder app
- Go to Settings > Telegram Configuration
- Enter your Bot Token
- Enter your Chat ID
- Tap Test Connection to verify
- Enable Telegram Forwarding
- Return to Home and enable SMS Forwarding
| Permission | Purpose |
|---|---|
RECEIVE_SMS |
Intercept incoming SMS messages |
READ_SMS |
Access SMS content for forwarding |
INTERNET |
Send messages to Telegram API |
POST_NOTIFICATIONS |
Show status and error notifications |
WAKE_LOCK |
Keep CPU active during SMS processing |
RECEIVE_BOOT_COMPLETED |
Auto-start service on device boot |
FOREGROUND_SERVICE |
Run persistent background service |
SCHEDULE_EXACT_ALARM |
Schedule service restart if terminated |
The app uses a foreground service to ensure reliable SMS forwarding:
- Startup: Service starts via
Application.onCreate()or boot receiver - Foreground Mode: Displays persistent notification (required for Android 8.0+)
- Wake Lock: Partial wake lock prevents CPU sleep during processing
- Watchdog: Internal timer checks health every 5 minutes
- Auto-Restart: If killed unexpectedly, AlarmManager reschedules restart
Service Termination (unexpected)
│
▼
onDestroy()
│
▼
Schedule AlarmManager
(5 second delay)
│
▼
RestartReceiver
│
▼
SmsForwarderService.startService()
The spam detector supports multiple rule types:
- Keywords: Block messages containing specific words/phrases
- Patterns: Regex patterns for flexible matching
- Blacklist: Block specific phone numbers
- Whitelist: Always allow specific numbers (overrides other rules)
Forwarded messages use HTML formatting:
📨 New SMS Received
📱 From: +1234567890
🕐 Time: 2024-01-15 10:30:45
💬 Message:
Your SMS content here...
- Disable battery optimization for the app
- Enable "Allow background activity" in app settings
- Add app to device-specific "protected apps" list (Xiaomi, Huawei, etc.)
- Check if forwarding is enabled on Home screen
- Verify Telegram configuration in Settings
- Test connection using the "Test" button
- Check if message was blocked by spam filter (History > Spam tab)
- Ensure notification permission is granted
- Check notification channels are enabled in Android settings
- Verify notification settings in app Settings
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ktor - HTTP client for Telegram API
- Jetpack Compose - Modern Android UI toolkit
- Room - SQLite abstraction layer
- DataStore - Preferences storage



