SmsAlarm is an Android app that watches incoming SMS-style notifications and plays a loud alarm when a target traffic message is detected.
Current detection rule: trigger when a new notification from an SMS app contains the text
上海交警.
- Chinese full project documentation:
docs/项目文档.md
- Lets you toggle monitoring on/off from a single button in the main screen.
- Uses Android's Notification Listener API (not direct SMS read permissions) to inspect posted notification text.
- Filters likely SMS notification sources (
Google Messages,AOSP MMS, or package names containingsms). - Debounces alerts to avoid repeat triggers in a short interval.
- Starts a foreground alarm service that:
- raises alarm/media volume to max,
- requests audio focus,
- loops
res/raw/alarm.mp3, - shows an ongoing notification with a Stop Alarm action,
- auto-stops after 10 minutes.
- Runs a low-priority foreground keep-alive service while monitoring is enabled.
- Kotlin + Android SDK
- minSdk 29 / targetSdk 34 / compileSdk 34
- AndroidX Core + AppCompat
- Gradle (Groovy DSL)
app/src/main/java/com/example/smsalarm/MainActivity.kt
UI entry point, permission prompts, monitoring toggle.app/src/main/java/com/example/smsalarm/SmsNotificationListener.kt
Notification listener and message matching logic.app/src/main/java/com/example/smsalarm/AlarmService.kt
Foreground alarm playback and stop behavior.app/src/main/java/com/example/smsalarm/KeepAliveService.kt
Foreground keep-alive notification/service.app/src/main/java/com/example/smsalarm/MonitorConfig.kt
SharedPreferences-backed monitor enable/disable state.app/src/main/AndroidManifest.xml
Permissions, services, listener declaration.
The app requests / depends on:
POST_NOTIFICATIONSFOREGROUND_SERVICEFOREGROUND_SERVICE_MEDIA_PLAYBACKFOREGROUND_SERVICE_DATA_SYNCMODIFY_AUDIO_SETTINGSWAKE_LOCK
It also requires manually enabling:
- Notification access for this app (
Settings > Notification access) soSmsNotificationListenercan receive notification events.
- Monitoring must be enabled in the app.
- A new notification is posted.
- Notification package must look like an SMS app.
- Notification text/body must contain
上海交警. - Debounce window check passes.
AlarmServicestarts as a foreground service and plays alarm audio.
- Android Studio Hedgehog+ (or compatible)
- Android SDK 34
- JDK 11
./gradlew :app:assembleDebugInstall from Android Studio or with ADB:
adb install -r app/build/outputs/apk/debug/app-debug.apkapp/build.gradle expects a keystore at ../smsalarm.keystore and reads credentials from environment variables:
KEYSTORE_PASSWORDKEY_ALIASKEY_PASSWORD
Then build:
./gradlew :app:assembleReleaseversionCode is derived from Git commit count (git rev-list --count HEAD).
Note: shallow clones are rejected; fetch full history before building release/versioned artifacts.
- Keyword and package filtering are hardcoded.
- Debounce interval and play duration are currently fixed in code.
- UI is minimal (single toggle button).
- The app inspects notification text delivered by Android's notification listener system.
- It does not currently upload message content anywhere in this project.
- Evaluate your local privacy/compliance requirements before production deployment.