Home Brew Bike Speedometer
I have a phone mount on my bike, and one of the things I had a notion to use it for was to use my phone as a bike computer or speedometer. However I read that the vibration can damage a phone’s accelerometer over time so I was a bit wary of using the phone I use day to day for that. On the rare occasions I need navigation, it will be worth the risk for that, but not just to know my speed on my regular routes.
Thankfully I have a couple of old phones stashed away. The one I would have preferred to use, due to its relative newness and larger screen, was a Motorola Moto G5, but unfortunately it would no longer power on. I believe the power button was dodgy when I retired it. That left me with the Samsung Galaxy S GT-i9000 (what a mouthful), a 16 year old device with a 4” screen. And a removable battery!
When I powered it on I expected to find Android 2 point something, which I figured might be too old to be useful for anything. It turned out I had installed CyanogenMod on it at some point, but for some reason it was stuck in a boot loop. Once I figured out the three-finger salute to get into the recovery menu (home, power, volume up) I was able to reset it and it booted normally. The version of the Android base was 4.3.1, an improvement over 2.x at least. Nonetheless the prospect of installing an existing speedometer app did not look good. The app store was inaccessible as was much of the web due to a lack of support for TLS 1.2 (I think). I think I couldn’t find a speedometer app that supported an Android version that old even if I could get an APK of it.
To be honest, I’m not sure I looked very hard.
So I fired up Claude and vibe-coded… LOL jk I would never. I’m not really a fan of Android development but I can do it when I have to, so I set about building a basic app targeting SDK 18 as required for Android 4.3.
There were some challenges to this, both due to the hardware and the ancient API version. On the hardware side, the USB port is apparently dodgy, and ADB could only occasionally see the device. The GPS is also really crap compared to recent devices. I could not get a signal in my office, or indeed anywhere indoors, and even taking it out on the roof it took quite a while to get a location. Not much of a problem for actually using the app because I usually cycle outdoors, but it made testing a real chore. For a while I thought I had no way of even seeing stack traces from crashes, but it seems that when you disconnect and reconnect a device you can see the logs from the period it was disconnected, so that helped a lot once I realised it.
On the software side, the Android Jetpack libraries were not available, and a lot of documentation and advice refers to these rather than the legacy library. For ages I was getting crashes due to a method I had not implemented, onStatusChanged, because the documentation said it was deprecated. Turned out it was required on Android versions < 11, and even though I had 4.3 as my minimum, Android Studio did not flag its absence as a problem. Ah well. Should have RTFM a little more closely…
The UI I implemented emphasises the current speed, but shows the max speed achieved in the session and the current altitude as well. There is also an indicator for if there is a GPS “lock” (just goes to false if there hasn’t been a location update in the last ten seconds). I think it looks pretty elegant.
The code isn’t very interesting or anything, but here it is if you’re curious or have an old Android device you would similarly like to repurpose. I don’t really have any intention of maintaining it or creating releases of it.
The battery life is actually quite impressive. In some rough testing I did it lasted over 14 hours with the screen on for most of the time, but otherwise idle. I haven’t tried to determine the effective battery life when using the app, but I think it will be plenty for my purposes.