MCode: Feeling the Hour in Morse Code on Android
Checking the time usually means looking at a screen. Sometimes that is awkward: in a meeting, in the dark, or when you simply do not want to pull out a phone. I wanted a way to know the hour without looking or listening. So I built MCode, an Android app that vibrates the current hour in Morse code at the top of every hour, on the phone, on a Samsung Galaxy Watch, or both.
Why I built it
I build Android apps as side projects, and I wanted something small with a clear purpose that would still make me deal with real platform constraints. An hourly haptic clock fits that. The idea is simple, but making it fire reliably every hour in the background, after reboots, and across two devices is where the actual work is.
What it does
At 9 PM the watch vibrates ----., which is the digit 9. At 12 PM it vibrates .---- ..---, the digits 1 and 2. There is no sound, only haptic Morse.
- Vibrates the current hour in Morse at every :00.
- Keeps working in the background, including in Doze mode.
- Reschedules itself after a device reboot.
- Has independent phone and watch toggles in the phone UI.
- Includes a test button that previews the current hour's pattern, and a "Test Watch" button that triggers the watch remotely.
Timing
I kept the timing scheme close to standard Morse proportions so it is easy to feel the difference between symbols:
- Dot: 200 ms on.
- Dash: 600 ms on.
- Gap between symbols within a digit: 200 ms off.
- Gap between digits: 600 ms off.
Every digit is a five-symbol code: 0 is -----, 1 is .----, 5 is ....., 9 is ----., and so on. Because each digit has a fixed length, you can count symbols and know where one digit ends even before the longer gap arrives.
How it works
The project is written in Kotlin with Gradle (Kotlin DSL and a version catalog). It has two modules: app for the phone and wear for the watch. Minimum SDK is 26 because the VibrationEffect API is needed; target SDK is 34. Beyond AndroidX and the Google Play Services Wearable library, there are no third-party dependencies.
Turning an hour into a vibration
MorseCodeHelper holds the digit-to-Morse map and builds a VibrationEffect from the hour. It produces a waveform of alternating off and on durations using the timings above. Keeping this in one small class makes it easy to test with the in-app preview button.
Firing at exactly :00
AlarmScheduler uses AlarmManager.setExactAndAllowWhileIdle with an RTC_WAKEUP alarm. A plain inexact alarm would drift and could be deferred; the exact, allow-while-idle variant is what lets the alarm fire during Doze. The alarm goes to HourlyAlarmReceiver, which starts a foreground VibrationService.
Why a foreground service instead of vibrating straight from the receiver? A broadcast receiver has a very short window to do its work, and a long pattern could be cut off. The service calls startForeground with a notification, plays the vibration, and calls stopSelf() after the pattern's total duration plus 500 ms. That gives the vibration time to finish. On API 34 this requires the FOREGROUND_SERVICE_SPECIAL_USE permission.
Surviving reboots
Alarms are cleared when a device restarts. A BootReceiver listening for BOOT_COMPLETED reschedules the next alarm. The watch has its own equivalent, WearBootReceiver.
Phone to watch communication
The watch runs its own alarm, scheduler and vibration service, so it does not depend on the phone being nearby at the top of the hour. The phone only sends configuration and test commands, through the Wearable Data Layer:
- Enable/disable:
WatchSyncManagerwrites a data item at/mcode/configusingDataClient.putDataItem. On the watch,WearDataListenerService.onDataChanged()picks it up and callsWearAlarmScheduler.schedule(). - Test: the "Test Watch" button sends a message to
/mcode/testusingMessageClient. The watch'sonMessageReceived()startsWearVibrationService.
The split matters: a data item is persistent state that syncs, which suits a setting. A message is a one-shot command, which suits a test trigger.
Permissions
Exact alarms need SCHEDULE_EXACT_ALARM on API 32 and below and USE_EXACT_ALARM on API 33 and above. The app also declares VIBRATE, RECEIVE_BOOT_COMPLETED, FOREGROUND_SERVICE, POST_NOTIFICATIONS for the service notification, and REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to keep alarms reliable.
What I learned
- Background reliability is the real feature. The Morse logic is a few lines. Getting a vibration to fire on time through Doze, reboots and API-level permission differences is most of the project.
- Give each device its own scheduler. Having the watch run its own alarm means it keeps working when the phone is out of range. The phone is only a remote control.
- Choose the right Data Layer primitive. Data items for state, messages for commands.
- Foreground services buy you time. Finishing a timed pattern safely is easier inside a service than inside a receiver.
One trade-off to be honest about: the Morse helper is duplicated in the phone and watch modules rather than shared through a common library. For a project this size it was simpler, but a shared module would remove the risk of the two copies drifting apart.
Conclusion
MCode is a small app that taught me how much work sits behind a simple promise like "do this every hour." If you want to try it, the source is on GitHub under the MIT license, with debug APKs for phone and watch in the repository's releases folder. They are debug builds, so you will need to enable unknown sources to sideload them.