Was feeling a little bored, so I decided to throw together an application to forward all notifications from my Android phone to my desktop.
The Basic Process
- Android App – Create an Android application that hooks into the phone as an accessibility service. This service then listens for TYPE_NOTIFICATION_STATE_CHANGED events and sends a message to Amazon SNS (Simple Notification Service). This leveraged heavily off the AWS SDK for Android.
- Amazon SNS Topic – This topic receives the message and contains one Amazon SQS (Simple Queue Service) queue as a subscriber. (As a side note, I originally didn’t use Amazon SQS, but instead forwarded any SNS notifications to an email address. Emails from the SNS topic were then kept in a specific label which was monitored using IMAP IDLE. However, I had some problems with responsive and speed with this, so I decided to utilise SQS instead.)
- Amazon SQS Queue – This queue is set to keep messages for only 5 minutes (this prevents old alerts from showing up on your desktop.) Similarly, make use of the long-poll option so that you get almost-instant response from a polling client without having to constantly hit the server with requests for new messages.
- C# SQS Notifier – This is a basic C# program that polls the Amazon SQS Queue for new messages. If a new messages exist, it triggers an alert to Growl (which I used so I didn’t have to bother styling any sort of notifications or alerts.) This leveraged off the AWS SDK for .NET and the Growl .NET libraries.
- Growl – Growl for Windows to display alerts in a nice, styled manner.
Android Application – SNS Notifier
This was a lot simpler to build then I had originally expected. Especially after I found this article on the web.
Amazon SNS Topic
This is fairly simple to do. Create a topic and make sure your IAM user has permissions to access it.
Amazon SQS Queue
This also is fairly simple. Create a SQS queue, add permissions for your SNS topic to send messages to it and then ensure your queue settings are appropriate. Also, make sure your IAM user has permissions to access this.
C# SQS Notifier
This was a very small, custom C# application that simply runs on your desktop and fires off alerts to Growl when there’s something in your Amazon SQS queue.
This is what the final end product looks like! :)