Receiving Android notifications anywhere.
Hacking together a universal notification system for android.
I switched to an M1 Mac from a Kubuntu machine about a year ago. Everything’s been great so far. My productivity has skyrocketed; everything just works, and the battery life is awesome.
The only thing I miss is KDE Connect. More specifically, I miss the ability to receive my Android Push notification on my PC.
None of the ready-made solutions are simple or OSS enough, so I decided to build something myself.
Web-Push notification’s have been pretty standardized as of now, with even iOS supporting it. So I decided to build something on top of this.
The basic idea goes something like this:
The Android app will run in the background forever using NotificationListenerService and send all the notification parameters to my server via a post request. The server will then validate the request and do some basic filtering (spam checks and app validation). Post-filtering, it’ll send a web-push notification to all the devices I’ve subscribed to (mac,iOS, etc., doesn’t matter; basically anything with a browser in it).
I decided to do validation and filtering on the server instead of doing it on the device because (a) recompiling or installing the app for a new ruleset is a chore as opposed to just pushing the changes on the server and letting github actions do the magic, and (b) I can use much more powerful filtering on the server than on the device.
I haven’t done Android development or written Java in a long, long time, so I decided to use GPt4 to help me with that. I realized that it is terrible at writing anything but Python.
So a giga-ton of prompts and pasting Android API references in the context window later... It finally worked (sort of) in just about an afternoon of work.
Here’s some ugly code if you want to take a look (it directly sends push notifications from the app itself using a ready-made push notification provider (pushalert); I will implement the server-side features and my own notification server later).
**sort of, because my phone’s battery manager is aggressive asf. It kills any notification service when the device is locked. I've tried almost every solution from Don't Kill My App, but it’s still unreliable as hell. I might have to root my phone and make this a kernel function, or just switch phones all together.
I will post and update with server-side features soon.
Adios till then!